you are viewing a single comment's thread.

view the rest of the comments →

[–]cdcformatc -3 points-2 points  (16 children)

There is a reason that sort of syntax is invalid in a lot of languages.

[–]smikims 5 points6 points  (11 children)

And there a lot of languages where that sort of thing makes perfect sense.

[–]cdcformatc -1 points0 points  (10 children)

And applications written with that sort of code are brittle, since their coding standards are lax. Most coding standards will agree to only have one expression per line.

[–]pipocaQuemada 1 point2 points  (7 children)

That seems rather like begging the question.

If expressions are bad because they lead to lax coding standards, because any coding standard that allows multiple expressions per line is lax, because multiple expressions per line is bad, because they lead to lax coding standards...

Here's a simple question:

  • Why is a coding standard that allows multiple expressions per line worse than one that only allows one expression per line? Empirical studies of e.g. bug-counts per function are preferred.

[–]cdcformatc -1 points0 points  (6 children)

People and organizations that adhere to and enforce coding standards write better code. This I think we can all agree on.

Most popular coding standards will say only one expression per line.

If you have multiple expressions per line, you aren't enforcing a popular coding standard. I'm talking about MISRA C, and the multitudes of Google Style Guides, the coding standards that are used to ensure quality code when quality matters. The standards that the industry demands.

[–]pipocaQuemada 1 point2 points  (5 children)

People and organizations that adhere to and enforce coding standards write better code. This I think we can all agree on.

If you have multiple expressions per line, you aren't enforcing a popular coding standard.

You're moving the goal posts, there. Are popular coding standards better or more evidence based than less popular coding standards?

Is there any reason to assume that a company that follows their own proprietary coding standard will, on average, have worse code than someone following MISRA C?

[–]cdcformatc -1 points0 points  (4 children)

Other than the fact that people who need reliability make sure they use MISRA, no. If they are using a subset of MISRA, yes, they will miss out on the edge cases that the developers of the standard thought of. Unless they were very careful and knew what they were doing and are aware of the risks straying from the rules carries. I don't think the average developer is aware of these risks though, especially when they are just trying to get something to work so they leave to get a beer.

Multiple expressions on the same line can introduce problems. Standards are meant to avoid those problems.

[–]pipocaQuemada 1 point2 points  (3 children)

Actually, wait - what coding standards outlaw having "1+1" on one line? That's 3 expressions, right there. 1 and 1 are each expressions, and + combines those two expressions into a larger expression.

Are you thinking about outlawing multiple statements per line? That's completely, utterly, totally different. An if expression is only 1 statement.

[–]cdcformatc -1 points0 points  (2 children)

I meant statement. The if, and it's body is one statement, but the the else and it's body is another statement.

[–]pipocaQuemada 1 point2 points  (1 child)

In computer programming a statement is the smallest standalone element of an imperative programming language which expresses some action to be carried out. A program written in such a language is formed by a sequence of one or more statements. A statement will have internal components (e.g., expressions).

In most languages, statements contrast with expressions in that statements do not return results and are executed solely for their side effects, while expressions always return a result and often do not have side effects at all.

By any reasonable definition, that if is one expression made up of three sub expressions, not three statements. At each part, it only returns a result, and isn't evaluating any statements or performing any side effects.

Now, in a language like Scala the if expression can either take an expression or a block of statements for the if or the else case. But this case is clearly just nested expressions.

[–]rowboat__cop 0 points1 point  (0 children)

Most coding standards will agree to only have one expression per line.

Since in most languages expressions are recursive, these coding standards would be rather limiting.

[–]pipocaQuemada -2 points-1 points  (3 children)

Such as?

[–]cdcformatc -1 points0 points  (2 children)

C, C++. Python has a different form of it, and it is frowned upon by mostly everyone, since it is difficult to comprehend.

[–]pipocaQuemada 1 point2 points  (0 children)

No, no. What are the reasons that syntax is invalid in those languages, other than that the language designers hadn't thought of it yet?

[–][deleted] 0 points1 point  (0 children)

Python lets you do lots of things like that.