News for hackers. Stuff that matters.
Re:Alternative code styles by crehn on Monday October 15, 2018 @07:35AM (#18218893)
Nowadays I couldn't care less about what style is used. As long as the code is consistent and there's an easy way to adhere (clang-format, black, prettier, etc.) I'm happy.
Re:Alternative code styles by frou_dh on Monday October 15, 2018 @07:59AM (#18218984)
Put another way... if the proponent of a particular (serious) syntax style guide can't be bothered to automate it, then they are pissing in the wind.

I laugh when I see those 50-page English-language documents describing how some institution wants code to be formatted. Ain't nobody got time for that.

Re:Alternative code styles by bryanrasmussen on Tuesday October 16, 2018 @03:18PM (#18232334)
I worked at a place recently where someone (who left before me) argued seriously that automated syntax fixing shouldn't be brought into the millions of lines multi-project codebase with approximately a dozen developers with a 40% retention rate over any two year period because it would encourage bad habits by not properly punishing people for being bad.
Re:Alternative code styles by emodendroket on Monday October 15, 2018 @09:51AM (#18219610)
There are some limits to what you can automate but stuff like spacing should definitely be enforced by a tool.
Re:Alternative code styles by jeremy_wiebe on Monday October 15, 2018 @01:00PM (#18221442)
I feel like Prettier does a really good job with JavaScript.

What situations have you found where automated formatting doesn’t suffice or has these limits?

Re:Alternative code styles by paulddraper on Monday October 15, 2018 @01:25PM (#18221666)
Ordering code.

Some tools order/deduplicate imports. Prettier does not. [1]

And no tool that I've seen orders fields/constructor/method, etc.

[1] https://github.com/prettier/prettier/issues/949

Re:Alternative code styles by jeremy_wiebe on Monday October 15, 2018 @01:31PM (#18221714)
Interesting, yeah, that’s definitely missing. ESLint has rules for ordering, feels like it’d be a relatively simple addition to prettier.
Re:Alternative code styles by eropple on Monday October 15, 2018 @01:34PM (#18221750)
In JavaScript, imports sometimes (too often, really) have side effects. I don't know if it makes sense for prettier to do that, at least by default.
Re:Alternative code styles by michaelmior on Monday October 15, 2018 @04:06PM (#18223204)
I don't have a problem with anything that discourages imports with side effects. You can always ignore[0] any cases where this happens.

[0] https://prettier.io/docs/en/ignore.html

Re:Alternative code styles by paulddraper on Monday October 15, 2018 @02:13PM (#18222137)
In my experience, side-effecting imports are fairly uncommon.

But in any cases, all formatters allow you to selectively disable it for certain liners.

Re:Alternative code styles by dvlsg on Monday October 15, 2018 @05:01PM (#18223713)
Hopefully uncommon, anyways. Imports with side effects sounds like a nightmare to debug.
Re:Alternative code styles by paulddraper on Monday October 15, 2018 @02:14PM (#18222151)
> it’d be a relatively simple addition to prettier.

It would be, but as you can see in the linked issue, it was closed for being a non-goal. So, it's not likely to change.

(Prettier generally keeps the AST identical; i.e. whitespace and parentheses changes only.)

Re:Alternative code styles by chrisweekly on Monday October 15, 2018 @02:02PM (#18222037)
eslint and prettier are not mutually exclusive
Re:Alternative code styles by jeremy_wiebe on Monday October 15, 2018 @08:06PM (#18225277)
I didn’t mean to imply that. In fact we use eslint + prettier where I work.
Re:Alternative code styles by eberkund on Monday October 15, 2018 @04:08PM (#18223218)
I don't know if it supports JavaScript but Resharper does this for .Net
Re:Alternative code styles by reitanqild on Monday October 15, 2018 @05:37PM (#18224028)
I think all three major Java IDEs do this as well.
Re:Alternative code styles by edflsafoiewq on Monday October 15, 2018 @07:11PM (#18224876)
Humans format with rules that take into account semantic information, symmetry, and aesthetics. They know that a function call that gives the entries of a matrix is formatted as a grid for a reason even when the auto-formatter could fit it on one line. They know that that arm of the match that would be formatted weird if it were on its own is actually formatted well because it exhibits that case's consistency with the other cases in the match. Probably the most important formatting decision they make is to, rather than format a long line, break it into intermediate results and store them in local variables given human-meaningful names.
Re:Alternative code styles by seanmcdirmid on Monday October 15, 2018 @12:19PM (#18221028)
Many programmers are still committed to manual formatting, or fixed width fonts would have been obsolete already.
Re:Alternative code styles by dxhdr on Monday October 15, 2018 @12:59PM (#18221438)
Fixed width fonts let you quickly parse syntax. Syntax and semantics are equally important when reading code, whereas semantics are generally the only thing you need for understanding the written language.

That said, I haven't seriously tried programming using variable width fonts; maybe it's a well-kept secret to digesting code. Or maybe it's like Hemp Milk, there's a reason it hasn't caught on.

Re:Alternative code styles by seanmcdirmid on Monday October 15, 2018 @02:25PM (#18222251)
There is actually no evidence for that. Programmers in general seem to be faster with whatever they are used to. I personally have trouble parsing code in fixed width fonts versus proportional ones* because I’m used to the latter and the kerning of fixed width formatting annoys me. Keywords pop out easily with syntax highlighting in any case, making syntax pretty obvious.

* to be fair, I’d have trouble with a bad proportional font like Times New Roman, but I’m sure many would have trouble with Courier New on the other side, the specific font matters.

Re:Alternative code styles by diegoperini on Monday October 15, 2018 @01:33PM (#18221736)
I don't know if variable width fonts are a help or a disaster but I've been using multiple fonts in a single editor window for quite a while and the productivity boost is huge. My choices are Operator Mono (to typeset keywords and math stuff) and Firecode (to typeset ligatures). You can find my custom Atom stylesheet here if you want to try.

PS: The idea is not mine but I can't remember where I read the instructions about this editor setup, so Google is your friend.

https://gist.githubusercontent.com/diegoperini/853d54c8873e7...

Re:Alternative code styles by arama471 on Monday October 15, 2018 @01:00PM (#18221439)
wait are you saying fixed width fonts are only useful for manual formatting? because I find they make it much easier to read code.
Re:Alternative code styles by seanmcdirmid on Monday October 15, 2018 @02:58PM (#18222609)
There is no evidence that fixed width fonts have any advantage. It seems to be a matter of just what you are used to.
Re:Alternative code styles by PurpleBoxDragon on Monday October 15, 2018 @03:59PM (#18223132)
Fixed with fonts work well when you are using the alt key to work with multiple lines of code at once. This is especially helpful in the middle ground where the lines of code are similar enough that one can easily use a pattern but the extent needed to be written with that pattern doesn't justify creating some tool to automate writing the code.
Re:Alternative code styles by andjd on Monday October 15, 2018 @05:38PM (#18224037)
I strongly prefer coding in normal fonts instead of typewriter fonts. This is the primary reason that tabs are better than spaces. Working with a proportional width font in a space-indented file is always trying.
Re:Alternative code styles by nothrabannosir on Monday October 15, 2018 @01:07PM (#18221519)
Fixed width fonts are used for programming because of cargo culting. I tried programming in serif fonts only after a HN comment suggested it (would never have thought of it myself) and it's fantastic. Very readable. They were right.

And you can still manually format code, serif or monospace.

Proportional or monospace font choice is orthogonal to formatting.

(Edited to be more specific)

Re:Alternative code styles by seanmcdirmid on Monday October 15, 2018 @02:47PM (#18222499)
I prefer a San serif myself.

Mono space allows you to do manual alignment, eg if you want ascii art in your code or non standard formatting. Doing this with a proportional font means other people can’t read your code without using the same font.

Re:Alternative code styles by LiterallyDoge on Monday October 15, 2018 @10:21AM (#18219880)
Sign of an experienced architect. Read: "I'm old and too tired to argue, just don't break it ok."
Re:Alternative code styles by gagege on Monday October 15, 2018 @10:50AM (#18220136)
I'm 32 and I feel like I'm already at that stage sometimes. What will I be like when I'm 50?
Re:Alternative code styles by GnarfGnarf on Monday October 15, 2018 @12:47PM (#18221314)
I'm 70, push out production code every day (Horstmann style https://en.wikipedia.org/wiki/Indentation_style#Horstmann_st...), and I'm having the time of my life.
Re:Alternative code styles by marvy on Monday October 15, 2018 @10:19PM (#18225863)
Horstmann style looks like my ideal, but there's very little tool support for it, from what I've seen. For instance, if I want to swap the first two lines of an "if" statement, I can't use "line-based" copy/paste. Do you do things manually, or does your editor support it fairly well?

EDIT: looks like the tool support is so bad, Horstmann himself pretty much gave up: http://horstmann.com/unblog/2010-06-28/braces.html

Re:Alternative code styles by LiterallyDoge on Monday October 15, 2018 @11:27AM (#18220482)
Better.
Re:Alternative code styles by brixon on Monday October 15, 2018 @09:39AM (#18219522)
Consistency is key. Follow the style that the code already uses. For new apps, I make sure the team has the same style template and use the editor to format the page.

At the end of the day, it is important that the code looks like it was written by one consistent person and not 20 random different people.

Re:Alternative code styles by emodendroket on Monday October 15, 2018 @09:52AM (#18219617)
Unless the code you're working on combines different styles not only in the same project bet even in the same file.
Re:Alternative code styles by deckard1 on Monday October 15, 2018 @02:42PM (#18222454)
pet peeve #1 right here.

I really don't like the mandatory use of eslint (used as style enforcement), prettier, etc. When used as a bat to hit developers over the head, all this tells me is that the organization has too many anti-social developers that can't check their ego at the door.

Often someone will recommend a tool or technology in place of simple social common sense. If a developer can't follow the existing code style, they should be shunned. It's their problem. It's not a problem to solve with a fancy tool. You solve this particular problem by telling that person that they are an asshole. Using technology to solve social problems just exacerbates the problem.

All of that leads to a situation where we can't have nice things. You go into a codebase and see hundreds of exceptions to turn off eslint or whatever. Instead of just working around one-off style exceptions with common sense (who really gives a damn if a line needs broken/indented a certain way for a specific function) you have to plead with the style cops to let you off each and every time.

Developers really hate each other. Small organizations or teams tend to be a bit better in my experience. There is more camaraderie. But I often feel like I'm in a group of mercenaries, each ready to stab you in the back.

Re:Alternative code styles by britch on Monday October 15, 2018 @04:03PM (#18223181)
Linters save so much formatting time, I don't really see what it has to do with ego.

I certainly could go through and make sure all the spacing is exactly right, the functions/properties are in the right place, and rest of the rules of the styleguide are followed. But it's much easier to do when you get a warning, squiggly, or can use an autoformatter to match the rules.

I would never intentionally violate a rule, but I might forget a rule or miss a violation. With linters this is not an issue, the machine will let you know.

Everyone can focus on the correctness and quality of code and let the machine worry about making sure everything is formatted correctly.

Clearly the project you describe, where linting is disabled every other line is bad. But I wouldn't blame the linter for that. I don't know what can be done if a team has such a commitment to their own style that they put in the extra work to disable the linter.

A linter is not a tool for punishing people who violate a style guide, it's an assistant for people who are trying to follow a style guide.

Re:Alternative code styles by mruts on Monday October 15, 2018 @07:54AM (#18218959)
I don't think even you believes that. You're telling me you would be "happy" if every source file was one line?
Re:Alternative code styles by xboxnolifes on Monday October 15, 2018 @08:37AM (#18219168)
Just replace "style" with "half reasonable style".
Re:Alternative code styles by gdfasfklshg4 on Monday October 15, 2018 @09:03AM (#18219293)
Lint to personally preferred style on checkout. Lint to project style on checkin. Not a problem.
Re:Alternative code styles by hyperpape on Monday October 15, 2018 @09:50AM (#18219600)
Do you actually do this? From what I hear (and this makes sense from what I know about formatting/parsing algorithms) it's a huge pain, and not implemented for many languages.
Re:Alternative code styles by emodendroket on Monday October 15, 2018 @09:52AM (#18219621)
I have my IDE do all the formatting every time I close something and rarely personally intervene.
Re:Alternative code styles by hyperpape on Monday October 15, 2018 @10:07AM (#18219724)
That's easyish: it's a one-way street. The OP imagined something where everyone checks out code in whatever state it's in, applies their own system, then transforms it back, with no artifacts. That's hard.
Re:Alternative code styles by Ace17 on Monday October 15, 2018 @10:42AM (#18220056)
Same here, with a twist: the test suite does: global reformat (uncrustify or astyle, depending on the team), build, run the actual tests. As people almost always run the test suite before checking code in, all the project stays properly formatted.

My experience is: each time a team started doing this, all coding-style related discussions vanished, and it became a non-issue. It turns out it's a lot easier to accept a coding style you're not the one doing the actual formatting (this is why, BTW, I think stylechecking hooks alone are a bad idea).