The Official Funny Stuff Thread™
-
-
@boomzilla "I Sued"?
-
-
-
@doctorjones said in The Official Funny Stuff Thread™:
{ for (int i = 0; i != 10; ++i) { std::cout << "delete i->second;" << std::endl; } }
I was wondering what this extra layer of braces is for? This appears a few times in our code base.
Once upon a time, many moons ago; VS6 existed and was popular. It failed however to conform to a number of c++ standards.
One that it failed to adhere to was the lifetime of for loop variables created in the first section; leading to the following code failing to compile
{ for (int i=0; i<1; ++i){} for (int i=0; i<2; ++i){} }
because i was redefined by the second for loop.
The solution to this is to force the whole for loop into its own scope as you show.
Iterator variable leaking into outer scope is very useful in certain cases. Seriously, of all the things that are wrong with C++ and its ecosystem, you chose the least wrong one. There's myriad of even worse things, for example that if/loop condition is of type int, not bool.
-
@gąska said in The Official Funny Stuff Thread™:
Iterator variable leaking into outer scope is very useful in certain cases. Seriously, of all the things that are wrong with C++ and its ecosystem, you chose the least wrong one. There's myriad of even worse things, for example that if/loop condition is of type int, not bool.
Erm, then you define the iterator outside the loop like so:
int n; for(n=0; n<10;n++) { foo() }
And thus you've made it explicitly clear that
n
is available outside the scope of the for loop. No "gotcha" moment due to the fact that tons of language do not scope the iterator outside the loop otherwise.
-
@rhywden FFS stop editing your post when I'm reading it! It refreshed 3 times mid-sentence - and I'm on mobile so refreshing takes time. I know what you're saying even if your post is imperfect - hell, I'd have pretty good idea of what's your objection even if you hadn't posted at all!
That said. Declaring variable before loop looks ugly. What VC6 did wasn't fuckup, it was language extension. Makes code unportable between compilers, but it serves purpose. And when it's unwanted, the workaround is very straighforward. But doing the workaround by default, in every case, even with one loop, is stupid and pointless. Not to mention redefining
for
as one SO comment suggested, which makes the code EVEN LESS PORTABLE by introducing UB.
-
@gąska I can count the instances on one hand where I needed to access the iterator out of scope.
Also, I don't care about fucking "ugliness". I care about readability and clarity of purpose.
-
@rhywden said in The Official Funny Stuff Thread™:
I care about readability and clarity of purpose.
@gąska said in The Official Funny Stuff Thread™:
FFS stop editing your post when I'm reading it! It refreshed 3 times mid-sentence
-
@rhywden said in The Official Funny Stuff Thread™:
Also, I don't care about fucking "ugliness". I care about readability and clarity of purpose.
Ugliness is detrimental to readability. And when you have
for (int i
, there's no way you're going to confusei
three lines down with anything else (unless you're purposely obtuse, but then the problem is you, not the code).
-
@gąska said in The Official Funny Stuff Thread™:
And when you have
for (int i
, there's no way you're going to confusei
three lines down with anything else (unless you're purposely obtuse, but then the problem is you, not the code).-Wshadow
Bonus while trying to dredge my memory for the correct term for google:
-
@pjh MACHINE LEARNING
-
@pjh TIL about Global Climate Coalition.
-
@gąska said in The Official Funny Stuff Thread™:
@rhywden said in The Official Funny Stuff Thread™:
Also, I don't care about fucking "ugliness". I care about readability and clarity of purpose.
Ugliness is detrimental to readability. And when you have
for (int i
, there's no way you're going to confusei
three lines down with anything else (unless you're purposely obtuse, but then the problem is you, not the code).I've also seen plenty of "beautiful" code where someone went: "Looks nice but what the hell does it do?"
http://www0.us.ioccc.org/2015/burton/prog.c
Ain't that beautiful?
And "three lines down"? Yeah, because all loops are only three lines long...
-
@rhywden said in The Official Funny Stuff Thread™:
@gąska said in The Official Funny Stuff Thread™:
@rhywden said in The Official Funny Stuff Thread™:
Also, I don't care about fucking "ugliness". I care about readability and clarity of purpose.
Ugliness is detrimental to readability. And when you have
for (int i
, there's no way you're going to confusei
three lines down with anything else (unless you're purposely obtuse, but then the problem is you, not the code).I've also seen plenty of "beautiful" code where someone went: "Looks nice but what the hell does it do?"
http://www0.us.ioccc.org/2015/burton/prog.c
Ain't that beautiful?
For me, no. First, I'm a man, which means I don't notice traditional kind of beauty in things unless it's explicitly pointed out. Second, I'm slightly autistic, which means that even when someone pointed out the beauty of something and I see what they're talking about, I'm unable to appreciate it. Third, I'm on mobile, which means that even if I could recognize and appreciate beauty, I wouldn't be able in this particular case since the file is too wide to display entire line at once, I cannot zoom out more than 100%, and have no idea how to disable line wrapping and don't remember any non-line-wrapping editable textbox anywhere in my phone's system, nor am aware of any app or website that has one.
By beautiful code, I don't mean physical beauty. I mean concise, expressive code that says everything it needs to and nothing more. A code that's neither too enigmatic to be unable to think of locally, nor too bloated by terms devoid of meaning that exist only to satisfy compiler. A variable declaration without definition is such useless bloat.
And "three lines down"? Yeah, because all loops are only three lines long...
In the kind of code that reuses iterator variable, yes, it is usually about 3 lines of code (excluding braces). But in general, if your loop body is longer than 5 lines and there's more to your function than just this loop, it usually means that refactoring is overdue.
-
@gąska said in The Official Funny Stuff Thread™:
For every complicated problem in computer science, there is a simple, straightforward, wrong solution.
-
@gąska Well, I don't see that we'll agree on this. Basically, I'm of the opinion that if nearly every fucking language leaves the iterator in scope of the for loop then it's a bad idea to suddenly do this otherwise for no real good reason.
No, "beauty" is not a good reason. Also, it's not "expressive" in any way. It's implicit as demonstrated in the fucking SO question which lead to this discussion. If it was so goddamn "expressive" the question wouldn't have had to be asked in the first place.
-
@rhywden said in The Official Funny Stuff Thread™:
If it was so goddamn "expressive" the question wouldn't have had to be asked in the first place.
The question was about double braces.
-
@rhywden said in The Official Funny Stuff Thread™:
@gąska Well, I don't see that we'll agree on this. Basically, I'm of the opinion that if nearly every fucking language leaves the iterator in scope of the for loop then it's a bad idea to suddenly do this otherwise for no real good reason.
This is not "funny stuff". This is extremely unfunny bickering about unimportant boring stuff. Take it somewhere fucking else.
Here's something funny so I am not a hypocrite:
-
@gąska said in The Official Funny Stuff Thread™:
@rhywden said in The Official Funny Stuff Thread™:
If it was so goddamn "expressive" the question wouldn't have had to be asked in the first place.
The question was about double braces.
The question was about having to use workarounds (like double graces) in order to fix an unexpected gotcha.
-
@gąska said in The Official Funny Stuff Thread™:
First, I'm a man, which means I don't notice traditional kind of beauty in things unless it's explicitly pointed out.
There are several threads where people will be delighted to tell you that's utter .
-
@tsaukpaetra said in The Official Funny Stuff Thread™:
double graces) in order to fix an unexpected gotcha.
How about unexpected graces:
https://www.youtube.com/watch?v=9aS2115fmKA
-
@tsaukpaetra said in The Official Funny Stuff Thread™:
@gąska said in The Official Funny Stuff Thread™:
@rhywden said in The Official Funny Stuff Thread™:
If it was so goddamn "expressive" the question wouldn't have had to be asked in the first place.
The question was about double braces.
The question was about having to use workarounds (like double graces) in order to fix an unexpected gotcha.
No, the question was about the existence of double braces, period. The answer is that it's a workaround.
-
-
-
@gąska said in The Official Funny Stuff Thread™:
@tsaukpaetra said in The Official Funny Stuff Thread™:
@gąska said in The Official Funny Stuff Thread™:
@rhywden said in The Official Funny Stuff Thread™:
If it was so goddamn "expressive" the question wouldn't have had to be asked in the first place.
The question was about double braces.
The question was about having to use workarounds (like double graces) in order to fix an unexpected gotcha.
No, the question was about the existence of double braces, period. The answer is that it's a workaround.
{{}{}{{}{}{}{{{{}{{}{}}{{}{}}{}{}}{{{}{}{}{{{{}{}}}}{}{}}}{}}}}}}}}{}{}}}}}}}}{}{}}}}}}
-
-
-
-
@bb36e That means "a rare image of a shark stepping on a Lego", right? Not everyone speaks French here.
-
@blek neither do I, but I assume that what it's about
-
@blek said in The Official Funny Stuff Thread™:
Not everyone speaks French here.
I only had problems with the last word...
-
@boomzilla Do you have unicode license plates???
-
@topspin I think the heart is on every license plate in California or something like that.
-
@blakeyrat said in The Official Funny Stuff Thread™:
This is not "funny stuff". This is extremely unfunny bickering about unimportant boring stuff. Take it somewhere fucking else.
I agree with the first part, @mods.
That being said...
@gąska said in The Official Funny Stuff Thread™:
Iterator variable leaking into outer scope is very useful in certain cases.
What VC6 did wasn't fuckup, it was language extension. Makes code unportable between compilers, but it serves purpose.
No, you've got the order of events reversed. It's been that way because that's how MS implemented it before the C++98 standard was done. It wasn't their fault, but it also wasn't an intentional decision to "extend the language", as the default MS semantics of
/Zc:forScope-
has always been stupid.Seriously, of all the things that are wrong with C++ and its ecosystem, you chose the least wrong one. There's myriad of even worse things, for example that if/loop condition is of type int, not bool.
What do you mean??
#include <iostream> struct Expression { operator bool () { std::cout << "Expression is evaluated in bool context." << std::endl; return true; } operator int () { std::cout << "Expression is evaluated in int context." << std::endl; return 1; } }; int main() { if (Expression()) { std::cout << "foo" << std::endl; } }
$ a.out Expression is evaluated in bool context. foo
-
-
@topspin said in The Official Funny Stuff Thread™:
What do you mean??
I remember reading somewhere about at least one version of C++ using int instead of bool for conditions. Though I couldn't reproduce in ideone.
-
@blek said in The Official Funny Stuff Thread™:
@topspin I think the heart is on every license plate in California or something like that.
No, but it is one of a few non-alphanumeric symbols you can request on a custom license plate. The others are a 5-pointed star and a hand. The heart is the most common.
-
-
@hardwaregeek said in The Official Funny Stuff Thread™:
No, but it is one of a few non-alphanumeric symbols you can request on a custom license plate.
@hardwaregeek said in The Official Funny Stuff Thread™:
a hand
How many fingers stretched, and which one(s)?
-
@zecc All five (discriminates against the six-fingered man). Example plate from the CA DMV website:
Apparently there is one symbol I didn't remember, "+".
-
@hardwaregeek Those are apparently special series (Kids) plates.
The hand is not part of the license number.You can select position of the symbol on the plate, and one of the four symbols.
-
@obeselymorbid I'd forgotten they're special series plates, but that doesn't contradict what I wrote. They're still non-alphanumeric characters (symbols) one can have on customized, extra-cost plates.
-
-
@topspin said in The Official Funny Stuff Thread™:
@boomzilla Do you have unicode license plates???
"No, that's not my license plate you're looking for. Mine has a Cyrillic В, not Latin B."
-
@bb36e I sometimes see the moon during the day too. I'm such a rebel!
-
-
-
-
@boner said in The Official Funny Stuff Thread™: