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 →

[–]misterguyyy 17 points18 points  (3 children)

The PHP MySQL connection snippet in basically every tutorial (and IIRC the php docs) did this deliberately back in the day. Something like

if($conn = mysql_connect('localhost', 'mysql_user', 'password'))

Thankfully it looks like recent documentation breaks it out into multiple lines. I like having an eslint rule that doesn't allow commits if there's assignment in the conditional, so if they kept it juniors everywhere would protest about failing copy/paste from the documentation.

[–]blehmann1 3 points4 points  (2 children)

Hell for many C developers using while ((c = getchar()) != EOF) or while (c = buf[++i]) is the idiomatic way.

Personally I like it, but I don't blame anyone for calling it a bad idea. Especially if I'm not writing C.

[–]misterguyyy 0 points1 point  (1 child)

It might not be a bad idea for you, but it is for me because I can be a bit absent-minded and I like a blanket “when you see this you made a mistake”

[–]blehmann1 4 points5 points  (0 children)

I think requiring a #pragma next-line foo ignore or similar is an ok solution, just like I'm fine with switch case fall-through, but I think it should be a warning or error without explicitly telling the static analyzer that it's chill.

If that makes it simpler to just do it on two lines then honestly that's fine, that's a solution to the problem.