It's all Greek to me: Thoughts on code readability and aesthetics
avraam.dev
avraam.dev
This is why I'm in favor of auto-formatters like Black for Python. Nobody really likes it, but nobody really hates it either and you get used to it. What this does is that it completely removes the style component of the discussion, leading to better and more content-wise discussions of the code written.
Otherwise, it may be convenience, as I don't have to maintain consistency manually. May be, because in languages where there are multiple syntactic ways to do things (Python, JS), I want flexibility in emphasizing things. (Even if I don't overuse it.) It's hard for people who came up with formatting to predict everything what can be done in the language. People may use more imperative, more functional syntax, mix things etc. This may be even warranted in the context.
Of course, you can force a particular set of idioms, but this again becomes shifted to the context of a project or organization. In languages where the syntax is more uniform, it's easier to standardize formatting throughout the whole ecosystem. And indeed it is standardized in Lisp and Go for example - not in the C family for probably historical reasons.
languages where there are multiple syntactic ways to do things
Python zen says: the should be one (and preferably only one) obvious way to do it. Perl might fit your description better.> In Greece, we have a similar phrase [...] > Readable code, is a piece of code [...] > In Germany, they say [...]. > In 16th century, in the Habsburgermonarchy [...] > [...] but let me, tell you a secret: [...] > Readable code, is a piece of code [...]
(I'm from Bohemian village where we were taught commas delimits sentences and such usage would be technically incorrect, but I suppose there are different rules in other languages.)
As a native speaker, i can understand those sentences well enough, but they look wrong, and i wouldn't expect a fluent native writer to write them.
I have a Greek friend who is similarly scattershot with commas (eg "Hey send me, the photo of your office!"). I wonder if this comes from mapping some feature of Greek sentence structure onto English?
What I've noticed is that some people never learned how to use them. They just write a sentence (or a whole essay) and generously sprinkle some commas afterwards, normally wherever they would make a short pause. I've seen this with colleagues from Germany, Greece, Russia and the US.
Anyway, other than the last two examples, the examples above don't look wrong to me.
AP style, or Oxford and a subtle political commentary? ;-)
They should not appear between subject and verb (“Readable code, is...” or “let me, tell...”).
It’s been a long time since I got this stuff in school, so there’s probably a lot of subtleties I’m forgetting.
As we’re talking about comma usage in English, it may be worth noting that there is wide disagreement about the Oxford, Harvard, or serial comma[1] in lists; no matter which choice you make, it will look wrong to many people.
There might be some technicality/formality that insists otherwise but this is so natural a writing style, and so invisible as a result, I had to reread the examples a few times before I understood what you were asking about (thought initially you might be asking about the ... notation which is a bit more idiosyncratic and up for debate as to how to use correctly)
To express something well, you need a sense for all the different ways to express it, to be able to choose the right one. But to just express it, you only need one.
anecdote: naming is hard. I can code something in a few hours, and still not have ideal names after weeks. Some come the next day.
Lower is better.
The point is, and will continue to be, that a senior's opinion should be heeded or you disallow them from steering the ship away from the glacier that they know is there.
You can always justify everything with a reason. If your goal is to justify, then great, you did that. If your goal is to be effective, you need to stop trying to justify.
https://msfn.org/board/topic/158668-virtual-memory-on-usb/?d...
>From John Phillip Mustachio of Houston, this excerpt from the trial testimony of the plaintiff, whose first language is Greek.
Q. What I'm trying to do, Mr. Emmanonil, is to show that you have quite a bit of experience in owning and operating real estate, do you not?
A. No. The only one experience I have is just to - to know how is the valuable of the land is going to go up or down. That's I'm good only. But legal phrase like this one, I'm zero. Like I say earlier, I have gift know when is good piece of land or not. The rest of this stuff it's English to me.
Original link is down, the sentence can be found here:
https://www.texasbar.com/AM/Template.cfm?Section=Say_What_&T...
Somewhat Criminal by Jerry Buchmeier
VOL. 60 NO. 9 TEXAS BAR IOURNAL 991 October 1997
https://www.texasbar.com/AM/Template.cfm?Section=Say_What_ https://www.texasbar.com/Content/NavigationMenu/NewsandPubli...
You could even sort of brute force this without IDE support by reformatting everything to your preference on git pull and back to ground truth on git stage/push, but when it comes to diffs, merges, etc, you must work in terms of the ground truth formatting. That's not even to mention doing stuff like PR reviews in online tools, not in your local editor/IDE. Going back and forth between the two like this would probably just be counter productive, you're better off just thinking in terms of the ground truth formatting from the start, I'd say.
I think while it might be possible under a very narrow set of limitations and usecases, it's probably just a very leaky abstraction to try to 'hide' the actual formatting of code in a text file.
I'm not dismissing the default formatter, it's obvious you still need one canonical representation of the code, but I don't think you should view it as "hiding" the formatting. In my view, it's more like opening a web page with one browser or another, or with one device or another. It always looks a bit different. Or maybe I have a theme configured on my main browser or whatever. I like to have my preferences, but if I have to look at the page from another browser, it's not a big deal either. The extra configuration might not be worth it or slightly inconvenient in some cases, but I doubt it's counter productive. The same way as I might prefer to read/write with a certain font or use this or that color palette.
Maybe the takeaway is that code is more personal for some people than we like to generally admit. You are talking in a language and you want to be able to express yourself as comfortably as possible. I mean, we have had turing-complete and even "productive/decently ergonomic" languages for a while, and yet a lot of people keeps coming up with new languages, because they are much more than just a tool to get things working. We want to express ourselves as we "think", and formatting may be a small part of that, but it's still a part of it.
I guess that's what's missing to make this work for code. The raw code is intended as the final representation to the end user.
Maybe what you'd need to make this work is to build in the concept of formatting to the source control itself, so all the way through the tooling you could 'render' the code as you'd like to see it, and do all operations on it using that view (including diffs, etc). Maybe sort of like you can with syntax highlighting, except with positional formatting instead.
QBASIC mostly removed line numbers.
By myself later
When forced to wade through what seemed
So clear at the time
Take, for example, JavaScript's double-equals == versus triple-equals === comparison operators. (I already know you have a strong opinion on these!) The language designer saw fit to include both. Now, if I introduce one bug where I need to use === explicitly instead of ==, should I advocate for a ban the use of == across the entire program? How about if I introduce this bug twice? Three times? What if I've only heard from a senior dev that triple-equals is "bad"? Or should we test the least-experienced member of the team and let their understanding make the decision for us? What happens when that team member gets more experience, do we lift the ban?
Double- versus triple-equals example is probably one of the most clear cut trade-offs and worth exploring. What about all of the other rules? Double versus single quotes, for example? What about declaring arrays using array-literal syntax versus using the new operator?
=== wasn't introduced until ECMAScript 3 in 1999, originally there was only == when the language was created in '95.
The accepted wisdom is to prefer the newer === in the interest of clarity and consistency. With ==, it's easy to forget about one of the types it overloads (e.g. string vs. number) when making changes to existing code, and correct-looking code may behave unexpectedly for one of these types.
Other language features cause other confusions.
Quotes generally boil down to arguments about escaping, and have good reason for existing. Having a rule for when to use what quotes should be pretty inferable from when you need to use what quote to escape the data in question.
New array vs literal is more a pure aesthetics issue, and I can only really say, choose whatever you think the majority of people would read faster. Don't be different just to be different, and move on.
However a lot of the arguments over code review come from (sometimes) aesthetic preferences about code decisions. Should this be pulled out as a function? What should it be named? Should this be inlined or pulled out as a variable? Is ~A or ~B more readable or ~(A and B) (the latter ends up causing the ugly sandwich (!( in languages like C++ or Java), etc etc.
These don't have automated solutions, but can nevertheless spark impassioned arguments.
I agree every language has what I call warts, but some are definitely worse than others.
I find there's little allowance for time spent thinking about the poor sucker who has to read my code, lest the sprint burndown chart suffers.
That's why code linters and formatters are so important. When applied correctly, it's the closest we can come to having the entire codebase looking like it was written by one person. A single standard you can learn once. Go and Dart are good at this.