Setting up your editor: indentation and encoding - encoding

I'm developing a small project with some friends and we're facing some indentation issues. Each of us is using a different editor (we all have different favorites :) and we also are on different operating systems.
What is the best solution to be able to all develop together and set our programming editors so indentation and encoding is the same? What settings do you recommend and why?

You should have your version control system handle the line ending problems. In SVN, the "svn:eol-style" property can be set to "native" to handle auto-converting the line endings. I assume your code is ASCII or UTF8 so you don't have problems with character encoding.
As far as formatting goes, you'll have to choose roughly some style, such as where to put the braces, but there's no reason you have to have the same indent style, provided you use the same number of indents. That's a confusing statement, so allow me to explain: nearly every IDE ever has the ability to set tab widths to any value you want. If one team member likes to indent 2 character widths, another 4, that's fine. One tab character stored in the file can display either way based on IDE settings. Just configure your IDE to indent with tabs and then set the tab widths per your desires.
(at the risk of starting a flame war, this is why I am solidly in the camp of tabs in the tabs vs spaces war. strangely, the spaces folks seem to consider this very feature the reason to use spaces... I will never understand them).

If you are all insistent to have your own indentation settings, then you will need to use exclusively the tab character to indent the code. (Provided your various editors support this).
This approach is counter to the general consensus of using spaces and only spaces for indenting purposes.

Whatever you do, I recommend converting tabs to a common number of spaces. I know Eclipse can do this on the fly, but I'm not sure if edits like gvim can. In any case, with all spaces it is not up to the individual editors/IDEs to interpret how many spaces make up a tab. Also, if anyone's using a Windows editor/IDE, set it to use Unix-style newlines, so that you don't get the annoying ^M at the end of every line when you edit in a different OS.

Related

How to add support for a custom non-unicode font in VSCode?

I have a custom fantasy script which looks like this (just the text portion):
It is a monospaced font built with FontForge. How can I add support for it to VSCode, so I can type in ASCII (like the left side here), and it outputs the random UTF-8 symbol mapped to the custom font in VSCode? So I can then save the file and have it be either a bunch of gobbledygook characters or the ASCII characters I originally typed?
Ideally this could be a plugin, so if you know of an open source VSCode plugin which I could use as inspiration, that would be a perfect answer as well.
I see how to set a custom font in VSCode, but (a) that is globally, and (b) it doesn't necessarily solve the typing problem. I just really would like to know how to do this, not necessarily requiring an answer to implement it.
Recommended UX is to have a "separate keyboard" for it, meaning typing the keys on the keyboard would result in different values. Maybe something like that can be done on a per-file basis?

What is the difference between empty space (>> >> >>) and empty space(......) in eclipse ide?

I know that,empty space (>> >> >>) in eclipse occurs due to use of keyboard(Tab) and empty space(......) occurs in eclipse due to use of Keyboards(Space bar) in the java editor.
What is the significance of it in programming and in the editors? Why is it shown differently in the Eclipse editors? What is the actual use of it and where it helps?
Can it allow to represent in the same way for, characters like new line(\n),vertical tab (\v),form feed (\f) etc.?
There are three ways of indenting: spaces, tabs and hybrid.
Spaces are environment-invariant: if you are indenting by two spaces, it will be two spaces in every terminal, every editor. Different programming languages have different coding style mores. E.g. Ruby is usually written with two-space indents, Python with four-space ones. Some people like space-based indentation, and can be very vocal about it.
Tabs will usually see people indenting by exactly one tab. It is up to the environment how to display it. The default is usually one tab in every 8th column, but editors will usually be able to adjust this. That way, if you disagree with a colleague about how many spaces are best, each can set their own environment as they wish. Some people like tab-based indentation, and can be very vocal about it.
Hybrid is a nightmare. If you mix spaces and tabs, expect trouble, as it will typically happen that you will encounter pieces of code that are horribly misformatted, wherever that colleague touches it. Avoid hybrid indentation at all costs. The only people who don't absolutely hate hybrid indentation are those who haven't dealt with it yet, or don't understand why any of this is happening.
Now, it is very hard to avoid the hybrid indentation if you don't know which indentation method is actually present in the file, especially if your editor is helpfully emulating tabs when you have space indentation, e.g. by deleting the whole indentation level when you press a single backspace (as is normal in most editors).
Furthermore, there are some horrible programming languages (such as Whitespace and Makefile) that semantically distinguish spaces and tabs, and it is thus critically important to see what each character actually is.

Using Scala & IntelliJ, show unicode arrows but don't change source-code

Scala allows to use the Unicode characters ← (\u2190) for <- and ⇒ (\u21D2) for =>
There are questions with answers on how to replace these characters (e.g. here and here) upon writing and even using post-processing (e.g. scala-style). These solutions however change the actual source-code. This means that if I'm using the Unicode style and my colleague isn't, we'll get a mix of styles in our source-code. Which in turn is something I dislike. (Meaning I'd rather use ASCII style arrows to prevent mixing styles.)
So I'm looking for a way to have a solution in the presentation-layer and not in representation. (like changing number-format using dot or comma for the decimal separator,.. it's not stored differently on disk.)
I'm aware that I could have Git do some funky stuff like it it does with line-endings for Windows, but I don't want to depend on Git for this. I just want IntelliJ (or Eclipse if someone knows how to fix it in Eclipse) to show me the Unicode arrows when it encounters the ASCII character version (preferably at the appropriate place, i.e. pattern-matching and for-comprehension).
Is this even possible in editors like IntelliJ and Eclipse? I'm willing to do some digging and writing plugins etc., but I'd rather not if it's not needed.
Since posting the question, IntelliJ has added native support to view arrows as if they are 1 character (called ligatures apparently).
From their whats new page:
We've added support for monospace font ligatures. To enable ligatures, go to Settings → Editor → Colors & Fonts → Font, choose a font that supports ligatures, e.g. FiraCode, Hasklig, Monoid or PragmataPro and select Enable font ligatures option.
If you want to see the lambdas as an arrow you can use the IDE settings.
I will go to IntelliJ Editor settings -> background, now enable the option "Enable ligatures".

Tab vs Space indenting (Dreamweaver vs NetBeans) problem

I use Dreamweaver at work and NetBeans IDE at home, but in both cases project is stored at github. My problem is that NetBeans seems to be constructing code indenting out of spaces and when opened in dreamweaver or exported to github, indenting here and there breaks (moves unexpectedly further then it was intended or vice versa), although when opened again in NetBeans, goes back to normal. It has been pain for some time already. Is there any resolution to this?
I should say that we at work (and me including) prefer tab indenting.
It depends on the IDE's definition of a TAB. There are usually options within the IDE to indent using a TAB but turn the TAB into a given number of SPACES. I usually indent using TAB but have the IDE turn that into 3 SPACES. This means that it doesn't matter what I (or anyone else) use to read my code later the indets are always the same.
In NetBeans you need to look in the Code Editor options but I have no idea where to find the settings in Dreamweaver.
Its been known that one should use double space rather than tab, because that fact that different IDEs define how the tab button works DIFFERENTLY.
For example, emberjs team require contributor to use double-space rather than tab for formatting the code.
It make sense that to use something recognized in common without an IDE, so that the code structure will not be a problem in a highly collaborated coding team environment.
HOWEVER, if customization of how a tab works in an IDE is enabled, tab will be a great time saver in this case-- Press twice the button cost 200% of the time to press one obviously :)
Hope that helps!

Tabs and spaces conversion

I would like to automatically convert between tabs and spaces for indentation when I commit/update code to/from our repository. I have found the AnyEdit plugin for eclipse, which can convert directories of files. Not bad for a start, but does anybody have more expierience on how to handle this? Or maybe know of an Ant script or something else?
Make sure you have your editor set to use spaces instead of tabs.
Select all text and hit CMD + I on mac or CTRL + I on windows.
Why not just use the code formatter and/or cleanup function? It has settings that take care of that stuff for you. You can even have it run automatically on save.
Edit: As Peter Perháč points out in the comments, this only answers half the question. I don't have any practical experience, but you could try the Maven Eclipse Format Plugin to format from a Maven build.
Unfortunately, that's Maven only, and I know of no light-weight command line formatter. But if you happen to use Maven, you can bind the format goal to the proper phase, and if you set Eclipse to auto-build, it would format on update.
Depending on the SCM tool (git, svn, etc), you could also create a hook that runs the build (but it might be a bit too heavy-weight for that).
I use the AnyEdit plugin to auto-convert tabs to spaces on the save of a file. I also configure the base text editor (from which pretty much all the others derive) to insert spaces instead of tabs. This sounds redundant, but what it does is ensure that I don't insert any tabs, and any file that I edit that already has tabs will be converted as soon as I save it.
Tabs have no place in source code. If someone else looks at the file with their tab-stops set to a different value, they lose most alignment/formatting anyway.
(Of course, if you have Makefiles that you edit directly, you'll want to make sure their tabs are retained. But in my projects, if make is used at all the Makefile is derived from a different source, such as a Makefile.PL in Perl.)
A bit overkill, and only something to attempt with certain repository products that can handle it, but a hook script to call indent or astyle could do the trick. It'll format everyone's code the same way for every file, depending how you write the hook script, and it'd have to be pre-commit of course.
You may lose alignment/formatting by using tabs instead of spaces if and only if the tabs are not at the beginning of the line. Never use tabs insides lines, always use tabs at the front of lines. This allows you to use your editor to adjust to your desired indent level without impacting your co-workers view of the file. Challenge: Find an example where tabs at the front of the line loses alignment.
I use Kedit for just this thing. It also natively converts text files from Macintosh, UNIX and MS-Dos. Since it's an older editor, I use one of it's scripts to handle unicode files.
You might also want to look at some of the other smart editors.
I use Eclipse for Java EE developer 4.6.0 Neon. I use http://marketplace.eclipse.org/content/anyedit-tools