News for hackers. Stuff that matters.
Re:Clear is better than clever [pdf] by jodrellblank on Monday May 06, 2019 @09:30AM (#19839195)
They are confusing and misleading to anyone new to your code base.

But why should that be the main thing to be concerned about and prioritise? In what way are they "misleading"? Is it really the state of the industry where a new person cannot learn a codebase, has no time or effort, and cannot read a single line of the language they were hired to work on, and that's the person we should build everything for?

Does it work like that in any other industry?

Re:Clear is better than clever [pdf] by 5trokerac3 on Monday May 06, 2019 @09:35AM (#19839235)
> Does it work like that in any other industry?

Yes, it does. Imagine you were a new underwriter at an insurance company and your predecessor used the shorthand nomenclature for every detail on the accounts you're taking over, and failed to write out any of the detailed reasoning behind why they chose to approve or deny claims. How much longer would it take for you to be able to fill their shoes than if they had been just a little bit more descriptive in their documents?

> "Programs must be written for people to read, and only incidentally for machines to execute." - Harold Abelson

Re:Clear is better than clever [pdf] by userbinator on Monday May 06, 2019 @08:50PM (#19845425)
No, it doesn't. In most other industries, you are simply considered incompetent if you don't possess the skills or aren't willing to learn the ways of the trade. Look at aviation for example: pilots and ATC talk in jargon, acronyms, and abbreviations like it's a completely different dialect of English, anyone who complains that they can't understand would be laughed at and told to keep learning, and that's the way it should be.

Yet the software industry seems to have developed an illness of perception, that encourages the continual lowest-common-denominator dumbing-down of code and an aversion to learning. From what I've seen "collaboration" as a justification for this, and from the types of people who are proponents of it, it appears to be related to the effort of managers to attempt to turn developers into disposable and easily replaceable drones; something which everyone actually writing code should be against. In the trades, there's no lack of teamwork either, but the prevailing notion is "the least skilled/experienced learns from the most" --- only in software does there seem to be a strong counter-trend to that. Perhaps we should not encourage the degradation of our craft.

Maybe that quote should be modified slightly too: "Programs must be written for suitably qualified people to read"

Re:Clear is better than clever [pdf] by Cthulhu_ on Tuesday May 07, 2019 @05:54AM (#19847925)
> Look at aviation for example: pilots and ATC talk in jargon, acronyms, and abbreviations like it's a completely different dialect of English, anyone who complains that they can't understand would be laughed at and told to keep learning, and that's the way it should be.

Yes, but the jargon and language used is standardized; pilots don't get to put their own twist on e.g. formal communication with the tower when they come in to landing. You don't get to switch to idk, km/h when communicating your airspeed.

Re:Clear is better than clever [pdf] by userbinator on Tuesday May 07, 2019 @07:41AM (#19848485)
Yes, but the jargon and language used is standardized

...so is the ternary operator.

Re:Clear is better than clever [pdf] by jodrellblank on Monday May 06, 2019 @10:45AM (#19839877)
Did you see that it was me quoting that exact quote as something to argue against?

I don't know what shorthand nomenclature of insurance underwriting is, but if it's a standard part of insurance underwriting then I would expect a new hire to be familiar with it, or need time to become familiar with it.

If it's something separate like actual Gregg or Pitman shorthand English which the one underwriter used personally, unrelated to underwriting skills, then I wouldn't compare that to a programming language's built-in ternary operators.

Re:Clear is better than clever [pdf] by 5trokerac3 on Monday May 06, 2019 @02:14PM (#19842157)
> I would expect a new hire to be familiar with it, or need time to become familiar with it

Which equals more overhead than is necessary. Elegance over accessibility is always more expensive, no matter the product. In my experience, folks who are obsessed with "perfect" code over readable code introduce the most long-lasting, destructive bugs, because, at best, nobody wants to and, at worst, nobody can decipher their stuff.

Re:Clear is better than clever [pdf] by bryanrasmussen on Monday May 06, 2019 @09:57AM (#19839409)
I once had to maintain a chat app in which the first developer had written something like the following at some point:

if (statement = ref) { print(statement) } else { print('have you done everything right?') }

was I wrong to be confused as to what he might have intended with statement = ref? Because he was in fact using the language functionalities to express what he wanted. I just thought it looked confusing and misleading.

Re:Clear is better than clever [pdf] by masklinn on Monday May 06, 2019 @11:26AM (#19840269)
FWIW modern C compilers recommend double-bracing exactly for that reason e.g. in clang, by default, it triggers:

    test.c:3:17: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
      if (statement = ref) {
          ~~~~~~~~~~^~~~~
    test.c:3:17: note: place parentheses around the assignment to silence this warning
      if (statement = ref) {
                    ^
          (              )
    test.c:3:17: note: use '==' to turn this assignment into an equality comparison
      if (statement = ref) {
                    ^
                    ==
Re:Clear is better than clever [pdf] by coldtea on Monday May 06, 2019 @09:39AM (#19839260)
>Is it really the state of the industry where a new person cannot learn a codebase, has no time or effort, and cannot read a single line of the language they were hired to work on, and that's the person we should build everything for?

Seasoned 10x developers, titans of the industry, and all agree on simplicity and even they frequently make mistakes on easily confusable constructs such as nested ternaries (or even BS like forgetting a break in a switch etc).

It's not some bad "state of the industry" that calls for no such constructs.

If anything, it's amateurs and newbs, more self-confident than they should be (and less humble) that call for using any old crap in a language, and think that such constructs are only problematic if developers are "not paying attention" or are "ignorant".

Re:Clear is better than clever [pdf] by atq2119 on Monday May 06, 2019 @02:03PM (#19842039)
Yes, they all agree on simplicity. Part of the problem is that simplicity is not entirely objective.

As an extreme example, people familiar with mathematical notation have a hard time when they start using a programming language that uses '=' for assignment, because they intuitively understand it as asserting equality, which it isn't (x = x + 1 would be paradoxical). And yet we all here presumably think of assignment as something rather simple.

There are plenty of code bases where the ternary operator is used frequently. It's a more succinct (but less versatile) variant of the if/then/else expression that a number of languages have - do you find that confusing when nested?

The ternary operator is just as simple as if/then/else expressions. You may not be familiar with it, which can make it seem non-simple, but then we're just back to the observation that simplicity isn't entirely objective but subject to your background.

Re:Clear is better than clever [pdf] by voidwtf on Monday May 06, 2019 @10:16AM (#19839592)
Or it could be that it’s subjective and there is no truly objective answer.
Re:Clear is better than clever [pdf] by coldtea on Monday May 06, 2019 @11:24AM (#19840254)
Well, it could be if we had more research.

From my experience, and from my reading on tons of books, code, clean code suggestions, bug reports, etc, patterns of bugs are more commonly found on such code bits, that sacrifice clarity for succinctness or "clever points" (in fact that's the very premise of TFA).

Most respected elders in development also warn against those types of code.

Lacking objective research, that's the best we can get, and I'd say better than "it works for me".

Re:Clear is better than clever [pdf] by Retra on Monday May 06, 2019 @05:45PM (#19844236)
The mistakes that people make are not subjective. They can detect when they make a mistake, and must do so to correct it. When people make mistakes by using a syntactic construct, that's something can be measured, and people do measure it, which is one of the ways they develop syntax preferences. The problem is that we don't ever measure it in an unbiased and representative manner.
Re:Clear is better than clever [pdf] by Cthulhu_ on Tuesday May 07, 2019 @05:50AM (#19847907)
Yes. Go is intended for BIG codebases - millions of lines of code. You can't afford to have to squint and decypher one particular author's code style when you have to go through that amount of code.

It's much easier to go through a codebase if everyone uses the same code style and you get the least amount of surprises. This does however require you to give up your own ego, that is, you have to conform to the standard.

Re:Clear is better than clever [pdf] by Random_Person on Monday May 06, 2019 @09:35AM (#19839234)
Because you can already read your own code. Writing for yourself is bad code. Write for the next person that has to figure it out.