|
This is a very nice article on how to use exceptions: http://www.sysart.fi/news/9/37/Exceptions---the-big-picture/d,artikkeli
|
# ? Dec 2, 2012 14:28 |
|
|
# ? Jun 5, 2024 08:03 |
|
Gul Banana posted:- a background thread or detached process which reports on its failure
|
# ? Dec 2, 2012 15:54 |
|
Also, if you're rethrowing the exception then you're effectively not catching it at all, from a control flow point of view. You're just temporarily intercepting it and doing some debugging side effects.
|
# ? Dec 2, 2012 16:12 |
|
Ithaqua posted:The code example I gave above was like that from top to bottom. Every method started with a try block and ended with an empty catch. It was a program that was supposed to be run 24/7 (it wasn't a service because that's harder than a console application run on the task scheduler), so I guess the developer responsible never wanted it to crash. I think we've worked on the same application, in my case that wasn't even the worse horror. The worse horror was the 1000 line method that managed game states through a web of conditional checks juggling local and member variables. I renamed the method "gameManager" in case I didn't have time to rewrite it... Along with that there was something like : code:
|
# ? Dec 2, 2012 18:28 |
|
Plorkyeran posted:The first three are all pretty much the same as catching everything in Main; it's really more of that catching everything at a module boundary and translating it to a different form frequently makes sense. true enough
|
# ? Dec 2, 2012 18:37 |
|
Volte posted:Catching all exceptions in Main is fine for production releases, since in the event of a fatal error you can display a pretty error message with an appropriate amount of information rather than whatever normally happens (like a generic .NET exception message followed by an illegal operation), plus you can generate an error report that can be sent in. Nope, this is still wrong. .NET offers several events (such as AppDoman.UnhandledException) that you can (and should) hook to achieve this, without writing a try/catch at all.
|
# ? Dec 2, 2012 20:16 |
|
Zhentar posted:Nope, this is still wrong. .NET offers several events (such as AppDoman.UnhandledException) that you can (and should) hook to achieve this, without writing a try/catch at all.
|
# ? Dec 2, 2012 20:29 |
|
A clusterfuck of genuine coding horrors: http://facepunch.com/showthread.php?t=1226297
|
# ? Dec 3, 2012 01:21 |
|
^^^^^facepunch posted:>Another method : Create a Dictionary<string, string>, fill it with your characters and their replacements, then replace the characters one by one by their representations in the Dictionary You know, I really embarrassed myself in my first coding interview. I had a lookup table that didn't need any sort of order on it, but I insisted it should be implemented as a linked list despite multiple prompts from the interviewer. I guess some people just kinda do that whenever or something Amarkov fucked around with this message at 04:16 on Dec 3, 2012 |
# ? Dec 3, 2012 04:13 |
|
quote:Here's my O(n) or O(2n) implementation (depending on pre-existence of the target buffer): Tell me more about your constant factors in asymptotics
|
# ? Dec 3, 2012 04:15 |
|
Volte posted:I could be wrong but I'm pretty sure that will not prevent the standard .NET exception window from showing. You can use both at the same time but I'm pretty sure you need try/catch to actually absorb the exception and display something more user-friendly. You are, in fact, wrong. I've used them to replace the standard .NET popup with automatic error reporting.
|
# ? Dec 3, 2012 04:35 |
|
This isn't really a coding horror of any sort (well, maybe it is and I don't know it), but it made me laugh. I wanted to draw a "polygon graph" with the number of edges as a parameter, using TikZ, and came up with the following code:code:
Looks bizarre, right? The reason is that the PGF "mod" function returns a float, so I was basically doing things like \draw (0) -- (1.0). And TikZ uses syntax like (nodename.angle) to mean points on the perimeter of a node at the specified angle from the centre, so I was telling it to draw each line from the centre of one node to the right-hand side of the next.
|
# ? Dec 3, 2012 07:01 |
|
Zhentar posted:You are, in fact, wrong. I've used them to replace the standard .NET popup with automatic error reporting.
|
# ? Dec 3, 2012 11:12 |
|
I came across a real gem this morning (C#):code:
|
# ? Dec 3, 2012 15:49 |
|
Summit posted:I came across a real gem this morning (C#): Just because you can use keywords inappropriately by prefixing them with an @ doesn't mean you ever should.
|
# ? Dec 3, 2012 15:55 |
|
Ithaqua posted:Just because you can use keywords inappropriately by prefixing them with an @ doesn't mean you ever should. Unless you're using ASP.NET MVC, in which case adding CSS classes to any generated markup means having new { @class = "stupid-class" } all over the place. davejk fucked around with this message at 16:44 on Dec 3, 2012 |
# ? Dec 3, 2012 16:34 |
|
Summit posted:I came across a real gem this morning (C#): language design
|
# ? Dec 3, 2012 23:10 |
|
code:
|
# ? Dec 4, 2012 00:32 |
|
Zorro KingOfEngland posted:Is there a significance to that 4 having whitespace? They're paid by the line.
|
# ? Dec 4, 2012 01:15 |
|
Do we have a way to test something-or-other yet? About that... I was going to work on rewriting some of your stuff. php:<? protected function request_file_list($path){ $fp = fopen("/tmp/". $this->_out_path, "w"); $our_url = "http://some-url-whatever-flkshaflskdfhsaldkfhsfkh/". $path; $ch = curl_init($our_url); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_VERBOSE, false); # Not needed per PHP defaults curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_PORT, $this->_alternate_port); # can be left out by specifying the port in the URL curl_setopt($ch, CURLOPT_USERPWD, $this->http_username":".$this->http_password); curl_exec($ch); curl_close($ch); fclose($fp); $response = file_get_contents("/tmp/". $this->_out_path); unlink("/tmp/". $this->_out_path); # never heard of CURLOPT_RETURNTRANSFER I guess? return $response; } protected function request_file($file_path){ $our_url = "http://some-url-whatever-slightly-different-though/". $file_path; $ch = curl_init($our_url); $fp = fopen("/tmp/". $this->_file_path, "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_VERBOSE, false); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_PORT, $this->_alternate_port); curl_setopt($ch, CURLOPT_USERPWD, $this->http_username.":".$this->http_password); curl_exec($ch); curl_close($ch); fclose($fp); // notice this does not return the contents of the file // it is read elsewhere in the class, unlike the above one // these little 'gotchas' are everywhere } /* there are at least 2 other instances of this all of the comments are mine */ ?> clearly offended by the suggestion his code is subpar But that'd save like five lines! Yes, but it means that the only part of that method is the part that matters. I just don't think it's worth worrying about right now. The whole point of this rewrite is because nobody ever did this poo poo, so we ended up with zero functions. We're here to do it right this time, not make the same mistakes. It wouldn't be so bad, but he has two classes; class A has X() and Y(), and class B has X(), Y(), and Z() (and so on). X and Y are the exact same. And yet, he did not just leave them out of the second class and add inheritance. I wish I could rewrite all of this crap, but it's really specific bullshit and undocumented, of course.
|
# ? Dec 4, 2012 03:08 |
|
Zamujasa posted:Do we have a way to test something-or-other yet? There's a saying I've heard (and believe): If you write the same code twice, you're probably doing something wrong. If you write the same code more tha twice, you're definitely doing something wrong.
|
# ? Dec 4, 2012 03:12 |
|
Ithaqua posted:There's a saying I've heard (and believe): I call it my rule of 3. Do something once ok. Have to do it a second time? Grumble a bit but probably do it. A third time? Take the time to refactor that poo poo right then and there. Though I'm probably the horror for the 2nd time.
|
# ? Dec 4, 2012 04:22 |
|
C++ code:
see this article if you want to read about the plugin being rewritten
|
# ? Dec 4, 2012 04:54 |
|
Yeah, that's what clean room reverse engineered code looks like. I hope you never stumble into the wrong parts of glibc by accident.
|
# ? Dec 4, 2012 05:02 |
|
Suspicious Dish posted:Yeah, that's what clean room reverse engineered code looks like. I hope you never stumble into the wrong parts of glibc by accident. A line or three describing the methodology would be helpful though.
|
# ? Dec 4, 2012 05:07 |
|
Ithaqua posted:There's a saying I've heard (and believe): That's good advice I'm starting to take into account. I've always been more of a procedural guy (especially since I started with BASIC and progressed to PHP; C's pointers and lack of easy-to-use strings made my brain hurt years ago) and getting into classes and inheritance and all that poo poo is a pretty big shock. It's basically been non-stop self-obsolescence, but the time-frames here make it so that I can't go back and make a version two of the first thing I wrote (with the boss's "IT loving WORKS DON'T EVER TOUCH IT AGAIN except to implement these few things "... I do what I can. That's a good, simple rule, though. Doing things twice can be understandable (something I'm writing now requires two slightly-different ways of getting it to work that are different enough to not be worth melding at this point), but three is probably overkill regardless of the situation.
|
# ? Dec 4, 2012 05:18 |
|
Most of the time the methodology boils down to trial-and-error, and the result is "whatever works". With Nintendo it's even more of a mindfuck because not every game handles things the same way, and on the Wii at least the actual system can differ depending on game.
|
# ? Dec 4, 2012 05:20 |
|
What do you want for a methodology? They found something that works, they wrote code, and then it broke for a game, and then they fixed something for both. The way the system works wasn't properly worked out yet when they wrote the code, so they played around until something worked.
|
# ? Dec 4, 2012 05:49 |
|
Suspicious Dish posted:What do you want for a methodology? They found something that works, they wrote code, and then it broke for a game, and then they fixed something for both.
|
# ? Dec 4, 2012 06:28 |
|
It was directed at the guy who asked for a methodology.
|
# ? Dec 4, 2012 06:30 |
|
The Gripper posted:Games on the Wii can reimplement the operating system,
|
# ? Dec 4, 2012 06:35 |
|
Aleksei Vasiliev posted:Wait, they can? I knew that the OS is run off the game disc but not that they could do that. There's no hypervisor like there is with the PS3 and Xbox360. edit; I guess it's handy because it means Nintendo never has to worry about their system updates breaking games, and for developers since they don't need to wait for upstream changes by Nintendo for things like peripheral support e.g. Guitar Hero. The Gripper fucked around with this message at 07:04 on Dec 4, 2012 |
# ? Dec 4, 2012 06:56 |
|
The Gripper posted:Developers can reimplement parts if necessary, and a lot of Nintendo titles do that (most of the Marios, Zeldas etc.) Nope. IOS is solely developed by Nintendo, and every single version is available through the Nintendo Update Service ("NUS"). Some games have an update partition, but this is simply an offline mirror. It is against the developer agreement to modify IOS. Wii development is a whole other set of horrors; you're correct in that there is no OS or hypervisor running on the main CPU (IOS runs on an small ARM I/O bridge fan-named "Starlet" found in the GPU die). Things like the Home Menu are found on every game disc. If people want to know more about this, or the horrors of it, I can explain it. For now: remember when System Menu 4.0 added WiiWare launching direct from SD? They implemented it by copying it to Internal RAM, running it from there, and then deleting it afterwards, for various silly reasons related to how they set up their architecture. Suspicious Dish fucked around with this message at 07:16 on Dec 4, 2012 |
# ? Dec 4, 2012 07:10 |
|
The Gripper posted:I don't know if that was directed at me, but I was agreeing! Games on the Wii can reimplement the operating system, so a lot of the code is undocumentable since it's band-aids of the "oh, this game wants this to work a different way? Ok, here you go" kind, without actually delving into the why's of it (because it's irrelevant). Well you have magic numbers, it'd be nice to know how you came up with them so if something is off when you find another game you know what each knob does. I've seen far worse embedded code. At least they're not ignoring nice register and flag defines.
|
# ? Dec 4, 2012 07:12 |
|
Suspicious Dish posted:Nope. IOS is solely developed by Nintendo, and every single version is available through the Nintendo Update Service ("NUS"). Some games have an update partition, but this is simply an offline mirror. It is against the developer agreement to modify IOS. Suspicious Dish posted:EDIT: not sure what "SSMB" is. Were you talking about "Super Smash Bros. Brawl" (SSBB)? The Gripper fucked around with this message at 07:57 on Dec 4, 2012 |
# ? Dec 4, 2012 07:18 |
|
The Gripper posted:Huh, well it looks like there are a handful of games using their own version of IOS but they're all Nintendo titles (SSMB, Mario Galaxy), so I guess it's a thing but not a thing unless you're Nintendo. Other games besides the one you mention use IOS35 and IOS36. It's released to all developers, first-party or third-party, at the same time through the SDK distribution channels. EDIT: not sure what "SSMB" is. Were you talking about "Super Smash Bros. Brawl" (SSBB)?
|
# ? Dec 4, 2012 07:34 |
|
I didn't realise they were actually reused, though I knew they were available.
|
# ? Dec 4, 2012 08:35 |
|
Hughlander posted:I call it my rule of 3. Do something once ok. Have to do it a second time? Grumble a bit but probably do it. A third time? Take the time to refactor that poo poo right then and there. Though I'm probably the horror for the 2nd time. Looks like we've discovered the DRY principle for the second time in 5 pages. Except this time we're more serious about it.
|
# ? Dec 4, 2012 09:06 |
|
Wheany posted:Looks like we've discovered the DRY principle for the second time in 5 pages. Except this time we're more serious about it. SRP-driven caution in 5... 4...
|
# ? Dec 4, 2012 09:20 |
|
|
# ? Jun 5, 2024 08:03 |
|
Wheany posted:Looks like we've discovered the DRY principle for the second time in 5 pages. Except this time we're more serious about it. So if we continue this discussion on the next page, does that mean we have to go back and refactor our posts?
|
# ? Dec 4, 2012 09:27 |