Live data from Hacker News

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

lkml.org

81–90 of 140 posts

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

#81
post #74

Earlier quoted context omitted.

Indentation to identify blocks can break down in things like switch statements: switch( c ) { case 'A': simple_stuff(); break; case 'B': { int temporary_variable = 0; complex_stuff( temporary_variable ); } To me, the advantage of braces on newlines is it makes it extremely easy to tell where blocks start and end---whether you're using your favorite IDE, or reading the code on a blog, or reading the code with "cat". I…

Fundamentally, the problem is that braces are needed at all. Humans are bad at matching them up, so they don't match the humans' intention when indenting. Confusion. It's all backward. The IDE should SHOW you the blocks somehow (background tone changes etc), and let you edit the blocking explicitely. If they look wrong, you select and hit a key. Now you're in agreement with the compiler.

Yeah, this is one thing Python got right. You should indent anyway, and then the curly braces aren't needed anymore.

I don't know what the point is in pretending IDEs or advanced text editors don't exist.

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

#82
post #6

IIRC, if the argument to sizeof is a type, the parentheses are mandatory, anyway, so using it like it was a function is more consistent. I think the reason it is not a function from the standard's point of view is that C does not have any builtin functions (unless my memory totally fails me in this case), all functions have to be either defined locally or #included.

In C there are no functions that take a type as argument. So sizeof(type) is a special case anyway. I'm all for using sizeof like a function, but that doesn't make it consistent. sizeof is just a special syntactical construct. I like to think that sizeof is called an operator just for syntactic convenience much in the same way as typedef is a storage-class specifier.

There are standard macros (va_arg, I'm looking at you) that take a type as an argument.

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

#83

Earlier quoted context omitted.

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

I don't believe its equivalent. When I'm writing Scala code in the backend and have to switch to frontend I often find myself omitting the semi-colons but going back and fixing due to self-imposed coding conventions. For Javascript just as in Python or Scala, semi-colons are optional for a good reason.

In Python you usually don't add semi-colons, and it will bark when your intention is unclear.

In javascript you may omit semicolons, but the interpreter will guess your intention when it is ambiguous and it will probably guess it wrong.

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

#84
post #68

"Quite frankly, if you do this, you should be shot. " Ah, yes. No comment from Torvalds is complete without a gratuitous ad hominem.

This is not an ad hominem argument. This is merely blowing things out of proportion. This would be ad hominem (and non-sequitur):

"You're watching dancing bunnies, and you dare suggest we should remove the parens after sizeof?"

Attack on the person (watching dancing bunnies), used to discredit an unrelated opinion (parens after sizeof).

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

#85
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.

I thought about that regarding semicolons, optional braces, newline placement, consistent placing of whitespace in general; then I decided having the machine tell me where I need to do more work is all very well and good, but what I really want is a program that will do the work for me instead. So I wrote one: https://www.npmjs.com/package/jsclean

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

#86
post #80
post #73

I used to write return (0); I.e., with a space. I'm not sure if someone ever told or recommended me to do this, but the reason I did this was consistency with other C statements, because all C statements that take some kind of expression as a parameter (if, for, while) require it to be surrounded by parentheses. So it seemed logical to me to do the same with return. I've stopped doing it now, although some of the old…

I find parens around a return value/expression slightly annoying, but not annoying enough to have a debate over it. It doesn't make the code harder to read, IMHO. Whitespace between a function name and the arguments is significant, however, because with a function-like macro, there must be no whitespace between the name and the opening parenthesis. I've seen the following code in production code, for example: #includ…

You do need to omit whitespace between the name and the opening parenthesis when defining a functionlike macro, but it doesn't matter when you're calling it.

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

#87

Earlier quoted context omitted.

I don't believe its equivalent. When I'm writing Scala code in the backend and have to switch to frontend I often find myself omitting the semi-colons but going back and fixing due to self-imposed coding conventions. For Javascript just as in Python or Scala, semi-colons are optional for a good reason.

We would all be better off if semi colons had just been required in JavaScript. The problem is that semi colons are not actually optional in JavaScript. Instead JavaScript use ASI, automatic semi colon invasion, where the compiler attempts to determine where semi colons should go. Unfortunately the rules are complex, prone to certain errors, and I can't rely on everyone I ever work with understanding all of those rul…

http://blog.izs.me/post/2353458699/an-open-letter-to-javascr...

Please stop spreading FUD.

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

#88

Earlier quoted context omitted.

Exactly. I heard people arguing on the Internet that you should not add parentheses when sizeof is applied to an expression, only a type. I just cannot understand why they bother. Just add a parenthesis and it is always right. Much less cognitive burden.

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.

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

#89
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.

Agreed. I spend most of my time writing non-semicolon languages like Ruby, Haskell, Scala, Elixir, Clojure, and Python. As a result, I never developed the semi-colon reflex that a lot of Algol-family language users built up. I constantly forget semi-colons even after all these years, and my own inability to remember annoys me.

I used to skip semicolons in JavaScript because I could never remember to include them. Using a linter with Emacs made it a non-issue; I get a warning in my editor immediately when I miss one.

PS: I'm really enjoying Rust, so maybe this will be the language that finally forces me to pick up the semi-colon habit.

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

#90
post #75

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'.

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.
Post reply on HN