Live data from Hacker News

Humans should think of sizeof() as a function, says Linus Torvalds

lkml.org

91–100 of 140 posts

Re: Humans should think of sizeof() as a function, says Linus Torvalds

#91
post #76

Earlier quoted context omitted.

This is the same people that find it "better" to write JS without the semicolons.

The problem is that without a linter there's no punishment for missing semicolons. So really the argument should be that everyone should use a linter.

Oh, there's plenty of punishment. Avoiding the punishment in the difficult part. And you can do that the easy way or the hard way.

Re: Humans should think of sizeof() as a function, says Linus Torvalds

#92
post #31

Earlier quoted context omitted.

Another oddity of C that amuses me is the do/while loop without braces: int i = 4; do printf("hey\n"); while (--i > 0); Even though do/while is a keyword bracketing pair in C, it still only lets you use a single statement (because nested whiles). So everybody uses braces, and thus it looks quite disturbing without them.

Its not so disturbing when you consider that braces aren't special cased in the C grammar. They group statements so they can be used together where a statement is needed. From the grammar's perspective the "normal" way is without braces. It's just that all the C-alikes have gone a different direction with the way braces are parsed leading everyone to regard the original behavior in C as ugly warts.

for, if, and while without curly braces for single statement blocks are easily one of the worst things about C. It bites you in the ass every time. The balance between its utility and its capacity to cause bugs is so one sided, I don't understand why it's even taught to beginners. If you are teaching a new programmer that saving keystrokes is important, you're on the fast track to creating a shitty programmer.

Re: Humans should think of sizeof() as a function, says Linus Torvalds

#93
post #92

Earlier quoted context omitted.

Its not so disturbing when you consider that braces aren't special cased in the C grammar. They group statements so they can be used together where a statement is needed. From the grammar's perspective the "normal" way is without braces. It's just that all the C-alikes have gone a different direction with the way braces are parsed leading everyone to regard the original behavior in C as ugly warts.

for, if, and while without curly braces for single statement blocks are easily one of the worst things about C. It bites you in the ass every time. The balance between its utility and its capacity to cause bugs is so one sided, I don't understand why it's even taught to beginners. If you are teaching a new programmer that saving keystrokes is important, you're on the fast track to creating a shitty programmer.

That's pretty severe. Written with spacing, its really pretty clear what is meant by

   if (condition)
      Foo(x)
Braces are, in my opinion, an unfortunate necessity in some cases. They are a much larger cause of error than NOT using them ever could be.

An ideal IDE would make blocking visible (background tone change etc), and braces could be emitted automatically by the IDE without ever cluttering up the code shown to the programmer.

Re: Humans should think of sizeof() as a function, says Linus Torvalds

#94
post #88

Earlier quoted context omitted.

This is the same people that find it "better" to write JS without the semicolons.

Do semicolons make the code run faster? What is the advantage exactly? There is no downside to leaving them out.

AFAIK the only "benefit" to semicolons is that you can put multiple statements on the same line.

Re: Humans should think of sizeof() as a function, says Linus Torvalds

#95
post #75

Earlier quoted context omitted.

I would imagine once you get used to him and thicken your skin up a bit, it's no big deal. Hell, a little salty language and telling people they're being idiots when they are being idiots is not a bad thing. The best machinists and millwrights I've worked with were like that, and it was a good thing - you don't have time to ask politely when there are steal beams or a two-ton electric motor swinging towards you. C ca…

He literally says that those who disagree with his code style should be shot. That's completely unacceptable language to use and makes him sound like he hasn't mastered English. I'm not sure anyone should take c-language style tips from such a boor.

It's called hyperbole, it's quite common in english.

Re: Humans should think of sizeof() as a function, says Linus Torvalds

#96
post #66

I respect Linus greatly but the way he to talks to his fellow 'humans' is insanely confrontational, rude and disrespectful. It overshadows his arguments (which are usually very good) and throws people on the defensive. I'm grateful for all he has accomplished and shared with us but I imagine working with him is 'hell'.

http://www.catb.org/esr/faqs/smart-questions.html#keepcool

Keep in mind: that's the dipshit that thinks he's the avatar of Pan.

Re: Humans should think of sizeof() as a function, says Linus Torvalds

#97
post #92

Earlier quoted context omitted.

for, if, and while without curly braces for single statement blocks are easily one of the worst things about C. It bites you in the ass every time. The balance between its utility and its capacity to cause bugs is so one sided, I don't understand why it's even taught to beginners. If you are teaching a new programmer that saving keystrokes is important, you're on the fast track to creating a shitty programmer.

That's pretty severe. Written with spacing, its really pretty clear what is meant by if (condition) Foo(x) Braces are, in my opinion, an unfortunate necessity in some cases. They are a much larger cause of error than NOT using them ever could be. An ideal IDE would make blocking visible (background tone change etc), and braces could be emitted automatically by the IDE without ever cluttering up the code shown to the…

The only problem with this is if/when someone comes along and doesn't notice the missing braces and does

   if (condition)
      Foo(x)
      Bar(x)
Expecting Bar(x) to be part of the conditional. This can and does happen.

Re: Humans should think of sizeof() as a function, says Linus Torvalds

#98

Earlier quoted context omitted.

That's pretty severe. Written with spacing, its really pretty clear what is meant by if (condition) Foo(x) Braces are, in my opinion, an unfortunate necessity in some cases. They are a much larger cause of error than NOT using them ever could be. An ideal IDE would make blocking visible (background tone change etc), and braces could be emitted automatically by the IDE without ever cluttering up the code shown to the…

The only problem with this is if/when someone comes along and doesn't notice the missing braces and does if (condition) Foo(x) Bar(x) Expecting Bar(x) to be part of the conditional. This can and does happen.

I hear folks say that, but don't encounter it in the wild. Maybe once in 20 years so far. That construct, reading it just now, just screams out at me "Indentation error!"

Anyway it nicely illustrates the need to get braces out of there altogether. The programmers' intent is obvious; let the IDE 'make it so' by emitting braces in the generated code.

Re: Humans should think of sizeof() as a function, says Linus Torvalds

#99
post #66

I respect Linus greatly but the way he to talks to his fellow 'humans' is insanely confrontational, rude and disrespectful. It overshadows his arguments (which are usually very good) and throws people on the defensive. I'm grateful for all he has accomplished and shared with us but I imagine working with him is 'hell'.

http://www.catb.org/esr/faqs/smart-questions.html#keepcool

Making others feel warm and fuzzy is one of the most important things in life. I don't like that it's downplayed.

Re: Humans should think of sizeof() as a function, says Linus Torvalds

#100
post #24
post #15

Earlier quoted context omitted.

No, not always. Not in Go, or in Rust, or Ruby, for example. The assumption being in these languages that if is followed by an expression and that expression is parsed to its natural end anyway - but this only works if the syntax allows for that end to be found without ambiguity.

In Go, however, go fmt will remove the unnecessary parentheses. I was very annoyed at first, when I saw this, but I got used to it.

Does it generally do this in expressions, based on operator precedence, or is it limited to the outer parentheses on selected statements?
Post reply on HN