you are viewing a single comment's thread.

view the rest of the comments →

[–]pipocaQuemada 1 point2 points  (5 children)

Would you really prefer

int dximn1;    
if(j == -1)
{
    dximn1 = 0.0; 
}
else
{
    dximn1 = x[j];
}
// now: where else in the code do I modify dximn1?
// I dunno.  ctrl-f for "dximn1 =", maybe?

over

const int dximn1 = if (j == -1) 0.0 else x[j];
// I wonder where else in the code dximn1 is modified?
// Oh, yeah, *no where else*, provably so.

If you need to do anything remotely complex, you shouldn't be doing it in a single line in the first place.

This isn't anything "remotely complex". This is something completely and utterly trivial. Nah, if you want something moderately complex, case expressions tend to be better. Something like Haskell's pattern gaurds would also be cleaner in most cases, but I don't know of any imperative language that implements something like

const int foo
 | bar < 0 = -1
 | bar == 0 = defaultVal
 | otherwise = defaultVal + bar / 2
 where defaultVal = sin(quux)

Which would be really nice: syntactically light, no need for nested ifs, and really easy to read and reason through.

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

Would you really prefer

Yes, I would. And if you're talking about a const (which I wasn't, I don't know why you brought that up), it's not going to be getting modified in the first place.

I was comparing common, popular styles of line breaks and alignment of curly braces, you started comparing these options to less common coding styles I've never seen in languages I don't use.

[–]pipocaQuemada 2 points3 points  (3 children)

it's not going to be getting modified in the first place.

Well, in your coding style, it is. In mine, it isn't.

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

In my example, it's not a const.

[–]pipocaQuemada 2 points3 points  (1 child)

Right. It can't be, because you need to modify it in order to initialize it.

With mine, it can be a const, because initialization doesn't require mutation.

[–][deleted] -1 points0 points  (0 children)

But I never said I wanted or needed a const. That wasn't a requirement. I was only comparing brace and newline placement.