Programming Confessions Thread
-
@stillwater said in Programming Confessions Thread:
How many of you can smell the picture?
My entire respiratory tract smells like cigarettes anyway.
-
@Gribnit Do you smoke the cigarettes or the other way round?
-
@stillwater what, you mean sticking them up your ass?
-
@pie_flavor said in Programming Confessions Thread:
@stillwater what, you mean sticking them up your ass?
it must indeed be admitted that in soviet russia cigarette smokes me.
-
When I landed my first real development job, I didn't really know how sockets worked. Not as much exposure to real world programs in school as I would've liked. I knew that I was guaranteed at least one byte unless the buffer was cleared out. So when I had to send some LPR commands between a PC and a printer, I did it one byte at a time. Fortunately, it was only a couple of KBs, so it wasn't a big deal and the Nagle algorithm probably covered it up anyway.
TRWTF was going back to that company about a decade later and seeing that nobody had updated it to handle multiple bytes.
-
@Zenith said in Programming Confessions Thread:
When I landed my first real development job, I didn't really know how sockets worked.
Lots and lots of developers don't understand that.
-
@pie_flavor The ass is not normally considered part of the respiratory tract. But I'm sure there's an extremely rare genetic disease that a pedant will soon mention to correct me.
-
@Zenith said in Programming Confessions Thread:
I didn't really know how sockets worked
Maybe you should take a mechanic course
-
@mott555 said in Programming Confessions Thread:
@pie_flavor The ass is not normally considered part of the respiratory tract.
But he's talking out of his ass so much it might very well be.
-
@dkf said in Programming Confessions Thread:
@Zenith said in Programming Confessions Thread:
When I landed my first real development job, I didn't really know how sockets worked.
Lots and lots of developers don't understand that.
Most developers don't know most of the very basic stuff. Because one man's very basic stuff is another man's useless trivia. Like the distinction between real and virtual mode in x86 processors.
-
@Gąska said in Programming Confessions Thread:
Like the distinction between real and virtual mode in x86 processors.
You mean x86_32?
-
@boomzilla stop trying to gaslight me. You know it doesn't work and the only result is more debating.
-
@dkf said in Programming Confessions Thread:
@Zenith said in Programming Confessions Thread:
When I landed my first real development job, I didn't really know how sockets worked.
Lots and lots of developers don't understand that.
I don't.
I mean, I could look it up if I ever needed to know.
-
@Gąska said in Programming Confessions Thread:
@boomzilla stop trying to gaslight me.
Are you still talking about smoking cigarettes with your ass?
-
@dkf said in Programming Confessions Thread:
@Zenith said in Programming Confessions Thread:
When I landed my first real development job, I didn't really know how sockets worked.
Lots and lots of developers don't understand that.
-
@pie_flavor well, you're still a student. You're expected to not understand anything.
-
@Gąska As a Java programmer he is expected never to understand anything. I don't understand anything anymore, I used to though.
-
@mott555 said in Programming Confessions Thread:
The ass is not normally considered part of the respiratory tract.
The stomach is also not normally considered part of the reproductive tract either, but here we are...
-
I used goto once, in C#.
It was so unusual that code review passed through all senior developers in the company. After much discussion it was deemed the best solution to the problem at hand, and went to production.
I don't know if I'm confessing or bragging.
-
@MrL said in Programming Confessions Thread:
I used goto once, in C#.
How? I think goto is a reserved keyword that's also a compiler error in that language, if I recall correctly.
-
@mott555 said in Programming Confessions Thread:
How? I think goto is a reserved keyword that's also a compiler error in that language, if I recall correctly.
tl;dr: You can use it to break out of nested loops or to transfer control between branches of a
switch
. Apparently.
-
@mott555 said in Programming Confessions Thread:
@MrL said in Programming Confessions Thread:
I used goto once, in C#.
How? I think goto is a reserved keyword that's also a compiler error in that language, if I recall correctly.
Nope.
@dkf said in Programming Confessions Thread:
@mott555 said in Programming Confessions Thread:
How? I think goto is a reserved keyword that's also a compiler error in that language, if I recall correctly.
tl;dr: You can use it to break out of nested loops or to transfer control between branches of a
switch
. Apparently.You can use it wherever you want:
static void Main(string[] args) { for(; ; ) { Console.WriteLine("GOTO!"); goto stop_writing; } stop_writing:; goto real_stop_writing; Console.WriteLine("GOTO!"); real_stop_writing:; Console.ReadKey(); }
-
@MrL Your for loop is crying and I can sympathize.
-
for (╯°□°)╯︵ ┻━┻ {
-
-
@dkf said in Programming Confessions Thread:
tl;dr: You can use it to break out of nested loops or to transfer control between branches of a
switch
. Apparently.And there goes my belief that C# was a well designed language
Obligatory xkcd
-
@TimeBandit said in Programming Confessions Thread:
@dkf said in Programming Confessions Thread:
tl;dr: You can use it to break out of nested loops or to transfer control between branches of a
switch
. Apparently.And there goes my belief that C# was a well designed language
It was 2000. Nobody knew what they're doing back then. Cut them some slack.
-
public class ಠ_ಠ : Exception { /* is it not? */ }
-
@Gąska said in Programming Confessions Thread:
It was 2000. Nobody knew what they're doing back then.
That would explain WindowsME
Cut them some
slackswastika made of dicks.FTFCT
-
@TimeBandit said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
It was 2000. Nobody knew what they're doing back then.
That would explain WindowsME
Since we're already throwing xkcds around...
-
@TimeBandit said in Programming Confessions Thread:
And there goes my belief that C# was a well designed language
Shirley it's not that bad. By disallowing backwards gotos most problems are...
Fuck.
-
@TimeBandit said in Programming Confessions Thread:
Obligatory xkcd
After some verification
Of course
Note:
The goto operator is available as of PHP 5.3.
So they added it in June 2009, it's not a mistake made at the beginning and kept for backward compatibility
-
@TimeBandit
Back when I did PHP (PTSD flashbacks) I found a situation where a goto would have been useful, because extracting an inner block to a function or using exceptions felt like overkill.
I ended up usingdo { if(timetobailout) break; } while(false);
.Oh look, right thread.
-
@Zecc said in Programming Confessions Thread:
@TimeBandit
Back when I did PHP (PTSD flashbacks) I found a situation where a goto would have been useful, because extracting an inner block to a function or using exceptions felt like overkill.
I ended up usingdo { if(timetobailout) break; } while(false);
.Oh look, right thread.
Since this loop will only ever execute once, why have the loop? Plus I assume there'd be useful stuff in the code block after the if-statement.
-
@mikehurley
Because there is more than onetimetobailout
. My variant of that unholy pattern is:bool pass; for (pass = false; pass != true; pass = true) { if (timetobailout1) break; // error condition if (itsfine1) continue; // pass w/o timetobailout2 if (timetobailout2) break; // error condition }
e: bugfix
-
@Applied-Mediocrity said in Programming Confessions Thread:
@mikehurley
Because there is more than onetimetobailout
. My variant of that unholy pattern is:bool pass; for (pass = false; pass != false; pass = true) { if (timetobailout1) break; // error condition if (itsfine1) continue; // pass w/o timetobailout2 if (timetobailout2) break; // error condition }
Where would the work of the loop go? Is this a retry loop? Is this a process many items loop and stop after a while?
-
@mikehurley said in Programming Confessions Thread:
@Applied-Mediocrity said in Programming Confessions Thread:
@mikehurley
Because there is more than onetimetobailout
. My variant of that unholy pattern is:bool pass; for (pass = false; pass != false; pass = true) { if (timetobailout1) break; // error condition if (itsfine1) continue; // pass w/o timetobailout2 if (timetobailout2) break; // error condition }
Where would the work of the loop go? Is this a retry loop? Is this a process many items loop and stop after a while?
Also are those two different timeouts (maybe a if work list is empty vs more work items available?)? If they're the same and just being checked twice, why not just once per loop?
-
@mikehurley
As usual, I screwed up with the most simple snippet. See the bugfix.
It's essentially an equally bug-ugly, but less dangerous (because it's forward-only) replacement ofgoto
error handling.@mikehurley said in Programming Confessions Thread:
Also are those two different timeouts
-
@mikehurley said in Programming Confessions Thread:
Since this loop will only ever execute once, why have the loop? Plus I assume there'd be useful stuff in the code block after the if-statement.
This:
do { /* Do some work 0 */ if( !allOk ) break; /* Do some work 1 */ if( !allOk ) break; /* Do some work 2 */ } while(false); /* Do some work 3 */
is similar to this:
/* Do some work 0 */ try { if( !allOk ) throw new Exception(); /* Do some work 1 */ if( !allOk ) throw new Exception(); /* Do some work 2 */ } catch {}; /* Do some work 3 */
But without having to use exceptions for control flow inside just one function.
In particular it prevents actual exceptions for being thrown while still not needing a custom exception class.Edit: removed empty lines for readability.
-
@Zecc said in Programming Confessions Thread:
while still not needing a custom exception class.
And, most importantly, no GOTO
-
@Applied-Mediocrity said in Programming Confessions Thread:
@mikehurley
Because there is more than onetimetobailout
. My variant of that unholy pattern is:bool pass; for (pass = false; pass != true; pass = true) { if (timetobailout1) break; // error condition if (itsfine1) continue; // pass w/o timetobailout2 if (timetobailout2) break; // error condition }
e: bugfix
Doesn't
break
andcontinue
do the same thing here?
-
@TimeBandit
Effectively, what we've done then is what programmers do best - replace one problem by another, more ridiculous one@Zecc said in Programming Confessions Thread:
Doesn't break and continue do the same thing here?
continue
will setpass
totrue
,break
will not.
-
@Applied-Mediocrity Ah right, was only thinking in terms of the code inside the block. Nice pattern.
-
I once wrote something to the tune of:
/* Loop needs to run at least twice */ int work_done=2; while( --work_done > 0 ) { /* work */ for( whatever ) { if( some_condition ) { work_done = 1; } } }
-
@Zecc said in Programming Confessions Thread:
Nice pattern.
Nice shoes.
Well, readability concerns aside.
: So what does this loop do here?
: Well, it isn't really a loop...
: Is so. It saysfor
here.
: It only runs once.
: So why it's even necessary? Get rid of it!Timeline #1:
: It isn't a loop. I... fine... *writes 25 Exception-derived classes and a try { ... } catch { error = true; }, gets fired*Timeline #2:
: It isn't a loop. I... fine... *writes using gotos*
:velociraptor:: Om-nom-nom!Timeline #3a (does not happen):
: Ok, I will educate myself on error handling, design patterns and code readability.
*does so*Timeline #3b (does happen):
: *lies* Ok, I will educate myself on error handling, design patterns and code readability.
*goes on wtdwtf to r/w more nerdy funnies*
-
@Zecc said in Programming Confessions Thread:
@mikehurley said in Programming Confessions Thread:
Since this loop will only ever execute once, why have the loop? Plus I assume there'd be useful stuff in the code block after the if-statement.
This:
do { /* Do some work 0 */ if( !allOk ) break; /* Do some work 1 */ if( !allOk ) break; /* Do some work 2 */ } while(false); /* Do some work 3 */
is similar to this:
/* Do some work 0 */ try { if( !allOk ) throw new Exception(); /* Do some work 1 */ if( !allOk ) throw new Exception(); /* Do some work 2 */ } catch {}; /* Do some work 3 */
But without having to use exceptions for control flow inside just one function.
In particular it prevents actual exceptions for being thrown while still not needing a custom exception class.Edit: removed empty lines for readability.
In this example why are you checking status? Usually with exceptions you assume success until an exception is thrown at which point the additional steps are not run. One of the nice things about exceptions is you don't need to do C style status code checks. Doing a bool check is the same thing.
-
@mikehurley said in Programming Confessions Thread:
@Zecc said in Programming Confessions Thread:
@mikehurley said in Programming Confessions Thread:
Since this loop will only ever execute once, why have the loop? Plus I assume there'd be useful stuff in the code block after the if-statement.
This:
do { /* Do some work 0 */ if( !allOk ) break; /* Do some work 1 */ if( !allOk ) break; /* Do some work 2 */ } while(false); /* Do some work 3 */
is similar to this:
/* Do some work 0 */ try { if( !allOk ) throw new Exception(); /* Do some work 1 */ if( !allOk ) throw new Exception(); /* Do some work 2 */ } catch {}; /* Do some work 3 */
But without having to use exceptions for control flow inside just one function.
In particular it prevents actual exceptions for being thrown while still not needing a custom exception class.Edit: removed empty lines for readability.
In this example why are you checking status? Usually with exceptions you assume success until an exception is thrown at which point the additional steps are not run. One of the nice things about exceptions is you don't need to do C style status code checks. Doing a bool check is the same thing.
To be fair it also depends on what language you're in. If we're talking about C code, then fair enough. If you do this in Java or C# or similar, I don't know why you'd want this pattern unless you're using a library that didn't do the standard exception pattern.
-
@Zecc said in Programming Confessions Thread:
This:
do { /* Do some work 0 */ if( !allOk ) break; /* Do some work 1 */ if( !allOk ) break; /* Do some work 2 */ } while(false); /* Do some work 3 */
is similar to this:
/* Do some work 0 */ try { if( !allOk ) throw new Exception(); /* Do some work 1 */ if( !allOk ) throw new Exception(); /* Do some work 2 */ } catch {}; /* Do some work 3 */
But without having to use exceptions for control flow inside just one function.
In particular it prevents actual exceptions for being thrown while still not needing a custom exception class.Or this.
/* Do some work 0 */ if(allOk) { /* Do some work 1 */ if(allOk) { /* Do some work 2 */ } } /* Do some work 3 */
-
-
@Applied-Mediocrity said in Programming Confessions Thread:
@Zecc said in Programming Confessions Thread:
Nice pattern.
Nice shoes.
"Nice" in the same sense as DF is fun.