Tabs > Spaces, and other fundamental truths :-D
-
Guitar Hero 2 sessions at a previous company
You had entertainment devices in the workplace?!
The best we get is a Direc-TV fed TV that we're not allowed to change the channel on. It's always on spanish soap operas or something.
-
Yeah, that was my first "career" job, and unfortunately I haven't found another company like that in a LONG time. Sigh.
I think a lot of the problems I have with work is that I was spoiled by having a Greatest Work Environment Ever as my first job. And nothing since then has been even close.
-
I've never really understood in the first place what problem wireless controllers solved
When your couch is too far from the TV for the cord to reach.
That and apparently wires are passรฉ.
-
I use a PS4 joypad with the PC. If it needs power during a game I just plug it into the nearest wall socket and it seems happy enough.
-
Thank you for sharing?
-
Thank you for sharing?
Hey, everybody, check out that politeness! Blakey's new water bottle's already working!
-
Civilized discourse in action.
-
check out that politeness!
Don't worry, he was just saving it for the Status thread. ;)
-
My first job was exactly the same: Guitar Hero and/or Foosball matches during every single lunch break. I miss that a lot.
-
-
Sounds like my Jr. High.
Not a single person in that office was 30+, so the age kinda fits as well. ;)
-
You know what? I'm going to give him that one, because that's an asshole error.
-
-
-
Yes, although that's not what I meant, which was more like "that's the kind of error text an asshole who probably doesn't like his users would write." BITCH SPANK etc.
-
-
So you are for more federal powers?
-
Easy, secede the Union and rejoin your Queen and country as loyal subjects. I'm sure we can create a few counties for you, e.g. West Americashire, North-West Americashire, and maybe New Yorkshire.
I wouldn't want it to be too confusing
-
They've already got New England, and that's OK. The rest is largely to the west of that, So that's New Wales. New South Wales already exists, and is to the south, so consistency is maintained.
Which leaves them as the "New English", and the "New Thieving Sheepshaggers".
-
The SNP are going to be so mad you haven't proposed naming a region New Scotland
-
Isn't that Nova Scotia?
-
New Caledonia already exists.
Taking into account Arantor's Nova Scotia, the Porridge Wogs already have 2 new lands. Greedy (deep-fried) pie-eating bastards that they are.
-
-
Isn't that Nova Scotia?
โฆand now I know how to say 'Scotland' in Latin.
@tufty said:New Caledonia already exists.
Wait, Scotland has two of them?
@tufty said:pie-eating
Is more a Lancashire thing. You're right about the deep-fried thing though; Scotland is home of the deep-fried Mars bar, after all.
-
-
```
syslog(LOG_NOTICE, "%s completed: %s", cmd,
rc == 0 ? "Success" :
rc == 1 ? "Syntax or usage error" :
rc == 2 ? "Protocol incompatibility" :
rc == 3 ? "Errors selecting input/output files, dirs" :
rc == 4 ? "Action not supported" :
rc == 5 ? "Error starting client-server protocol" :
rc == 6 ? "Daemon unable to append to log-file" :
rc == 10 ? "Error in socket I/O" :
rc == 11 ? "Error in file I/O" :
rc == 12 ? "Error in rsync protocol data stream" :
rc == 13 ? "Errors with program diagnostics" :
rc == 14 ? "Error in IPC code" :
rc == 20 ? "Received SIGUSR1 or SIGINT" :
rc == 21 ? "Some error returned by waitpid()" :
rc == 22 ? "Error allocating core memory buffers" :
rc == 23 ? "Partial transfer due to error" :
rc == 24 ? "Partial transfer due to vanished source files" :
rc == 25 ? "The --max-delete limit stopped deletions" :
rc == 30 ? "Timeout in data send/receive" :
"Unknown Error"
);So what would the correct way to do this be? I'm not much of a programmer, so that looks verbose, but sane, to me.
-
Define a function containing a switch on all the values the enum
rc
can contain, which returns pointers to the static error message. Then use:syslog(LOG_NOTICE, "%s completed: %s", cmd, rc_string(rc));
-
Well that's pretty similar, no?
-
No it isn't. You eliminate a huge nested ternary and centralize your error codes.
In he header (probably):
enum foo_rc { FOORC_SUCCESS = 0, FOORC_USAGE = 1, FOORC_BADPROTOCOL = 2, ... };
In some C file related to foo:
const char * foo_rc_string(enum foo_rc rc) { switch(rc) { case FOORC_SUCCESS: return "Success"; case FOORC_USAGE: return "Syntax or usage error"; case FOORC_BADPROTOCOL: return "Protocol incompatibility"; ... } return "Unknown Error"; }
Usage:
syslog(LOG_NOTICE, "%s completed: %s", cmd, foo_rc_string(rc));
Result: Centrally defined error codes, error messages if your lists of codes go out of sync.
-
You eliminate a huge nested ternary
What's the difference between "a huge nested ternary" and "a huge switch"? I mean yeah, a switch probably optimizes somewhat better, but in this case where you're just about to hit I/O anyway it hardly matters, doesn't it?
-
This way you don't need to duplicate if you need the strings in a second location.
Also defining an enumeration of possible values centralizes which codes have which meanings, enum labels are picked up by the debugger, and the switch will generate a compile-time warning if you're not handling all enum values.
-
This way you don't need to duplicate if you need the strings in a second location.
No, that you get from refactoring it into a method.
Also defining an enumeration of possible values centralizes which codes have which meanings, enum labels are picked up by the debugger
No, that you get by defining an enum.
and the switch will generate a compile-time warning if you're not handling all enum values.
That's an argument (although that's only recently been added to GCC?)... but then you need a
default
case anyway so that an idiot who doesfoo_rc rc = (foo_rc)123456
doesn't break your code.OTOH, what if you can't change whatever returns
rc
to return anenum
? Do you just blindly cast an int?
-
That's an argument (although that's only recently been added to GCC?)... but then you need a default case anyway so that an idiot who does foo_rc rc = (foo_rc)123456 doesn't break your code.
We're still on RHEL5 at work and that GCC has that warning.
You don't want a default case, as that eliminates the warning. That's why the switch options all return rather than break, and the default is the return after the switch.
You could get the switch advantage by doing the switch inline I guess (you can set the default above the switch) but at 20 possible values this should be in its own function and not clutter the logic here. Unless this is already its own function, of course.
-
Though you're right the ternaries aren't my only problem with that code.
-
So what would the correct way to do this be? I'm not much of a programmer, so that looks verbose, but sane, to me.
something like this:
char* rcMessage; switch (rc) { case 0; rcMessage = "Success"; break; case 1: rcMessage = "Syntax or usage error"; break; case 2: rcMessage = "Protocol incompatibility"; break; default: rcMessage = "You get the idea"; break; } syslog(LOG_NOTICE, "%s completed: %s", cmd, rcMessage);
of course that's if it has to be inline. it's better for maintenance and testing to split that switch into a function that returns the correct message.
like @Pleegwat did in this post:
@PleegWat said:In he header (probably):
-
Ahhh, now I understand. Thanks!