|
Plorkyeran posted:It's not very hard to write a generic RAII container for c api things: I never get the type conversion operators right std::unique_ptr seems fairly reasonable for most such things, though. I'd be happier if I could squeeze the api_delete_a_thing in there at the type level so the call would be, like, inlined and everything, but that's probably just an imaginary concern.
|
# ? Jun 20, 2012 18:37 |
|
|
# ? May 21, 2024 00:18 |
|
That was meant to be C code. Unfortunately, there's no syntax highlighting for plain C. And yes, I know about the multiple labels trick, but I chose to keep it simple on purpose. And at least people aren't linking Djikstra on my rear end and calling me human scum this time.
|
# ? Jun 20, 2012 18:41 |
|
Suspicious Dish posted:I'm curious how people feel about the goto statement as an approach to this. I'm pretty sure this is the technique Rochkind uses in Advanced UNIX Programming. I think he wraps a macro or two around it, though... It really is the only decent approach I've ever seen.
|
# ? Jun 20, 2012 19:33 |
|
Lumpy posted:So I had to poke around in a homegrown CMS system that a client's old web dev shop wrote ~6 years ago. It is full of horrors, but the README file takes the cake: That README is still leagues better than a straight-up incorrect one.
|
# ? Jun 20, 2012 19:36 |
|
Suspicious Dish posted:I'm curious how people feel about the goto statement as an approach to this. HTTP/1.1 sends \r\n as line separators, and has a Host: header
|
# ? Jun 20, 2012 19:45 |
|
Since you won't take "it was dumb example code" for an answer, how about "it was wrong on purpose so that a copy/paste programmer wouldn't have any chance of making it work, promoting proper software engineering practices instead". Yeah, that's it.
|
# ? Jun 20, 2012 21:00 |
|
tef posted:HTTP/1.1 sends \r\n as line separators, and has a Host: header If it makes you feel any better, it won't get that far because the check after the call to my_socket_open() is inverted.
|
# ? Jun 20, 2012 21:44 |
|
No Safe Word posted:Yeah though I mean 99% of Stack Overflow is a horror anyway, those tags just ensure the deck is fully stacked. At least those of us that hang out in the PHP chat room are competent. We've formed a little mob of sanity enforcers and copy/paste "DON'T DO THAT" commenters to help spread best practice. It's sad that such things are necessary.
|
# ? Jun 20, 2012 22:37 |
|
Suspicious Dish posted:And at least people aren't linking Djikstra on my rear end and calling me human scum this time. The core Linux kernel developers are extremely competent C programmers, and their views on this subject are pretty informative.
|
# ? Jun 20, 2012 22:38 |
|
Lysidas posted:The core Linux kernel developers are extremely competent C programmers, and their views on this subject are pretty informative. I saw this excerpt in that conversation and felt it needed some attention: quote:> I thought Edsger Dijkstra coined the "gotos are evil" bit in his Oh Linus, never stop being a horrible dick.
|
# ? Jun 20, 2012 22:44 |
|
geonetix posted:I saw this excerpt in that conversation and felt it needed some attention: My new favorite image
|
# ? Jun 20, 2012 22:48 |
|
"Hey guys, I'm not very good at C, but you're doing it all wrong, could you change it to be more like what I learned about in my introductory programming class?" These people
|
# ? Jun 20, 2012 22:49 |
|
basically gently caress people who talk about something despite not knowing anything about it beyond the name of a famous paper
|
# ? Jun 20, 2012 23:08 |
|
Haha. Not a coding horror in itself, but I just realized that the UPS we have here at work is apparently powering 4 outlet strips, three of which make up a huge daisy-chain. It's really starting to reflect the way coding is done at this place. Basically: code:
E: Oh, they managed to plug the microwave into the UPS at one point a few months ago too. That was all sorts of fun! Zamujasa fucked around with this message at 23:22 on Jun 20, 2012 |
# ? Jun 20, 2012 23:14 |
|
That was actually really neat. I had just accepted that gotos are bad, but after reading that, I've changed my mind. The arguments against goto are pretty similar to the arguments I've seen against including pass-by-reference and operator-overloading in Java.
Safe and Secure! fucked around with this message at 23:36 on Jun 20, 2012 |
# ? Jun 20, 2012 23:30 |
|
Safe and Secure! posted:That was actually really neat. I had just accepted that gotos are bad, but after reading that, I've changed my mind. The arguments against goto are pretty similar to the arguments I've seen against including pass-by-reference and operator-overloading in Java.
|
# ? Jun 20, 2012 23:58 |
|
code:
|
# ? Jun 21, 2012 00:19 |
|
PrBacterio posted:Please don't do that. Yes, goto's aren't in and of themselves evil, and sometimes it's better to use a well-placed goto in place of some more complicated circumscription where it makes for cleaner and more readable code, but nobody should take that as a license to pepper their code with gotos all over the place. In practice, using a goto statement is a bad idea *most of the time*, which is why the rule exists and people are usually taught never to use them, because that is *generally speaking* correct. If you come across one of the exceptions to this rule, where your code would be cleaner when using a goto, you'll know and should probably just go ahead and do it anyway. But knowing when it is OK to break such a rule, which is so commonly taught for a very good reason, first requires you to understand why it is in place in the first place and thus, adhere to it in most cases anyway. Pretty much. Really when it's appropriate to use a goto you should be at the point of already asking yourself, "Really? Really?? Is this one of those 0.01% of cases? Well goddamn..."
|
# ? Jun 21, 2012 00:24 |
|
LOOK I AM A TURTLE posted:God drat do I hate "single point of exit" as a design philosophy. It's the cause of conditional blocks the size of skyscrapers that are impossible to parse when all you need is if (gently caress == null) return false; But of course when the functions are small single-point-of-exit is pointless because you can easily scan the whole function for returns. I have no use for single-point-of-exit as a design philosophy. If I'm going to use it for clean-up or whatever it's because that's the best way to write that particular function not because it's a good approach to programming in general.
|
# ? Jun 21, 2012 00:36 |
|
"Blanket rules" in programming are the worst thing.
|
# ? Jun 21, 2012 01:16 |
|
Dicky B posted:"Blanket rules" in programming are the worst thing. You have a funny way of spelling "PHP".
|
# ? Jun 21, 2012 01:19 |
|
Dicky B posted:"Blanket rules" in programming are the worst thing. Spoken like someone who hasn't had a co-worker try to sneak a for loop implemented with goto through a code review.
|
# ? Jun 21, 2012 01:27 |
|
teamdest posted:You have a funny way of spelling "PHP". This joke is old and tired. Please stop. PHP doesn't cause bad code (though it certainly helps), people do. PHP is a very practical and productive tool, and in the hands of a capable programmer, can avoid a lot of badness. I dislike almost everything about PHP, but since I have the privilege of working amongst good programmers, the PHP code I see at work is not crap. Good PHP is still going to be better than bad Python or bad Scala or what-have-you.
|
# ? Jun 21, 2012 01:42 |
|
Zhentar posted:Spoken like someone who hasn't had a co-worker try to sneak a for loop implemented with goto through a code review. Idiot coworkers aren't a reason to abandon useful tools wholesale.
|
# ? Jun 21, 2012 01:45 |
|
Suspicious Dish posted:I'm curious how people feel about the goto statement as an approach to this. If this were C I'd completely agree with the goto usage. OTOH, I don't know C++ that well, but wouldn't it be possible to wrap the response in an object and have the clean-up done be its destructor? ~*patterns*~ In Python you'd do it something similar. You'd have with response(butt) as poop: where response has its clean-up defined somewhat like a finally iirc. edit: I guess what I'm getting at is why wouldn't you use exceptions if this is C++? edit2: vvv Suspicious Dish posted:It only says "C++ code" because there's no C highlighter. xf86enodev fucked around with this message at 03:59 on Jun 21, 2012 |
# ? Jun 21, 2012 02:04 |
|
quote:I guess what I'm getting at is why wouldn't you use exceptions if this is C++? Because they're bad and dangerous and unclear. Other reasons may include legacy systems or legacy compilers that don't support them. A good reason is because your coworkers don't know how to write exception-safe code. Probably you don't either, assuming you're a randomly distributed C++ developer.
|
# ? Jun 21, 2012 02:34 |
|
xf86enodev posted:If this were C It is. It only says "C++ code" because there's no C highlighter.
|
# ? Jun 21, 2012 02:40 |
|
Suspicious Dish posted:It is. It only says "C++ code" because there's no C highlighter. We should get Radium to make it say C/C++ and drive all the C nerds and the C++ nerds into a rage.
|
# ? Jun 21, 2012 02:43 |
|
Vanadium posted:We should get Radium to make it say C/C++ and drive all the C nerds and the C++ nerds into a rage. Posting C/C++ code should just crash your browser. Posting Java would be fine though. But it will crash browsers trying to look at the post unless they have signed up to Oracle's Open Post Streaming Intellisense (Enterprise Edition).
|
# ? Jun 21, 2012 04:26 |
|
xf86enodev posted:Posting C/C++ code should just crash your browser. In the future, probations will be automatically handed out for posts that don't follow PEP8.
|
# ? Jun 21, 2012 06:17 |
|
Suspicious Dish posted:I'm curious how people feel about the goto statement as an approach to this. And what's wrong with doing this instead? C++ code:
|
# ? Jun 21, 2012 06:18 |
|
Because code that looks likecode:
But that said, yes, goto is often a workaround for "missing" language features. Structured programming is important. When your programming language doesn't support the ideal structure for this situation, emulating the proper structure with gotos is often far better than trying to hack something up with the control-flow structures it does support, which will end up even worse. As a quick example, nesting ifs like this for cleanup purposes is a lovely hack to compensate for the lack of deterministic destructors. Faking it with gotos is still a hack, but it's far less lovely than doing it with if statements.
|
# ? Jun 21, 2012 06:43 |
|
Gotos and returns keep your code from looking like >
|
# ? Jun 21, 2012 06:43 |
|
I noticed that I never free(request); in my code sample, so I'm actually leaking memory. Oh well.
|
# ? Jun 21, 2012 07:05 |
|
Zhentar posted:And what's wrong with doing this instead? Maybe goto is a useful tool but if your only reason for using it is because you hate nesting, I hate you. Edit; redleader posted:Today I saw some of the html output from our platform: The Gripper fucked around with this message at 09:39 on Jun 21, 2012 |
# ? Jun 21, 2012 09:35 |
|
Today I saw some of the html output from our platform:code:
|
# ? Jun 21, 2012 09:35 |
|
Doctor w-rw-rw- posted:This joke is old and tired. Please stop. I'm of the personal opinion that if you can't write clean, clear, and consistent code in PHP, the language is not the problem. Sure, it's missing a few features that you'd expect in, say, Java or python, or whatever else, but it works and it doesn't force you to write your code in one particular way.
|
# ? Jun 21, 2012 11:31 |
|
bobthecheese posted:Sure, it's missing a few features that you'd expect in, say, Java or python, or whatever else, but it works and it doesn't force you to write your code in one particular way. I don't quite think features are the problem in PHP. Horrors. I used to work on a HL1 based mod and most weapons were created by copy-pasting and changing a few values. Hmm. Let's run simian against the server-side codebase: code:
Compare that with regular HL1 MP SDK: code:
code:
KaneTW fucked around with this message at 12:01 on Jun 21, 2012 |
# ? Jun 21, 2012 11:54 |
|
tef posted:HTTP/1.1 sends \r\n as line separators, and has a Host: header It also requires the verb, then the url, then the version number. Doctor w-rw-rw- posted:This joke is old and tired. Please stop. quote:PHP doesn't cause bad code
|
# ? Jun 21, 2012 12:03 |
|
|
# ? May 21, 2024 00:18 |
|
Zhentar posted:And what's wrong with doing this instead? A complete lack of RAII.
|
# ? Jun 21, 2012 12:09 |