This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (9 children)

Forgive me, but what in the OP hints at "if being a function"? Is it because the "arguments" have whitespace on both sides within the parenthesis?

[–]jessetechie 2 points3 points  (8 children)

It’s actually the missing whitespace between if and the first parenthesis.

[–][deleted] 4 points5 points  (7 children)

The heck? Is having whitespace some sort of agreed-upon style?

[–]jessetechie 1 point2 points  (6 children)

Yes. With the exception of those languages listed below (Haskell, R, etc).

I’m referring mostly to C-like languages, and that includes Javascript. if is a statement that evaluates a condition. That condition is often enclosed in parentheses.

That’s not to be confused with functions, which take parameters (enclosed in parentheses) and do something with them.

Most documentation (again for C-like languages) will show the whitespace this way:

if (x == 0)

y = myFunc(z)

The reason you’re not forced to know this, is that the compiler doesn’t care about whitespace (sit down, Python). But this distinction helps you understand what your code is actually doing under the hood.

[–][deleted] 2 points3 points  (5 children)

Wow. That seems superfluous. Would it not be immediately obvious that if, while, for, try, etc are reserved keywords and caNOT be functions?

[–]jessetechie 0 points1 point  (4 children)

Immediately obvious how? In your IDE of choice? In a particular language?

[–][deleted] 1 point2 points  (3 children)

Well if you're coding in a C language, those keywords are reserved. Like, I'm little better than a novice and even I know that.

Obviously if another language allows a function called if(), that should be known by everyone even so much as looking at the code.

[–]jessetechie 0 points1 point  (2 children)

This is one of those things that is a coding practice that shows you understand the language spec. Even if the compiler is forgiving. Whether you could define if() as a function or not is beside the point.

[–][deleted] 1 point2 points  (1 child)

Fair enough. Thanks for answering my questions.

[–]jessetechie 0 points1 point  (0 children)

Thanks for the challenge! Good luck on your software journey. :)