|
Chuu posted:That "Standard module error handler" is where RAISE_ERROR lives, which in and of itself is a bit of a horror because before SQL Server 2012 you could not re-throw errors, which meant using RAISE_ERROR and more ugly boilerplate for reporting. It isn't ordinarily that bad - you're showing an example dealing with nested transactions and try/catch at the same time, and frankly you're probably better off structuring the logic of your stored procs so you don't have to deal with nested transactions if you're at the point where you feel like they are necessary for some reason.
|
# ? Jun 15, 2012 12:46 |
|
|
# ? May 21, 2024 02:16 |
|
Kim Jong III posted:Pretty much what Sinestro said, you're almost guaranteed to stumble into a viper's pit of hellish practices. There's just something special about PHP that brings out the worst in people. Even when you move into other languages! My boss is now doing PHP+VB6+Embedded system stuff and it still has some crazy ideas in it. Like how our board has 8 inputs, and those are mapped to "input.php?num=0" through 7... while num=8 is reserved for general "heartbeats" that the board sends out every so often. I got my major start in programming in PHP but I've tried to branch out to other stuff more than once (Javascript + jQuery, Lua, a little bit of 6502 for amusement). Hopefully I'm no longer making really awful horrors.
|
# ? Jun 15, 2012 14:47 |
|
To me that sounds more like EE's trying their hand at software than PHP turning their brains to mush (although that might be a factor)
|
# ? Jun 15, 2012 14:58 |
|
Wait, embedded PHP is a thing? ...I think I might need to stop buying appliances.
|
# ? Jun 15, 2012 15:03 |
|
To derail a little bit, what are some examples of really good code?
|
# ? Jun 15, 2012 16:00 |
|
ymgve posted:To derail a little bit, what are some examples of really good code? "Coding Bliss: post the code that makes your job wonderful." just doesn't seem as interesting.
|
# ? Jun 15, 2012 16:04 |
|
Internet Janitor posted:Wait, embedded PHP is a thing? My guess is that it's embedded code running on the board -> .NET to talk to a COM driver or serial port -> PHP to chat with the .NET code via a web interface. Zamujasa posted:num=8 is reserved for general "heartbeats" that the board sends out every so often. Heartbeats aren't a bad thing if you're dealing with external hardware, particularly if it's controlling something that is mechanical or potentially dangerous in any way. They let both sides of the connection know if the control line is broken so that everything can shut down to a safe state.
|
# ? Jun 15, 2012 16:06 |
|
ymgve posted:To derail a little bit, what are some examples of really good code? In before duff's device. Also, I really don't think you can call much code "really good" simply because the field is SO young and we are SO bad at it. I'd argue that we're still in the "cave painting" era of computer programming.
|
# ? Jun 15, 2012 16:06 |
|
There is no good code, only awful code and REALLY awful code.
|
# ? Jun 15, 2012 16:21 |
|
ymgve posted:To derail a little bit, what are some examples of really good code?
|
# ? Jun 15, 2012 16:49 |
|
Good code is simple and straightforward, and therefore utterly boring.
|
# ? Jun 15, 2012 16:59 |
|
PDP-1 posted:My guess is that it's embedded code running on the board -> .NET to talk to a COM driver or serial port -> PHP to chat with the .NET code via a web interface. It's actually some embedded language that talks to a PHP script; I meant that the use of PHP for most other tasks by my boss appears to have fried his brain. quote:Heartbeats aren't a bad thing if you're dealing with external hardware, particularly if it's controlling something that is mechanical or potentially dangerous in any way. They let both sides of the connection know if the control line is broken so that everything can shut down to a safe state. I know. It's not the heartbeat that's the in that, it's that it is an actual input number (8) instead of zero or nothing. It also means that we can't change the board, ever, as if we did then we'd have to use 0-7 and 9-16 for input numbers. That is, mostly getting at the point that the choice he made here is bizarre and does nothing but complicate things in the future, when the correct choice (0 for heartbeat, 1-8 on activity) is comparatively painless and simple, and would require literally no extra work on top of it.
|
# ? Jun 15, 2012 17:04 |
|
ymgve posted:To derail a little bit, what are some examples of really good code? code:
|
# ? Jun 15, 2012 17:06 |
|
Plorkyeran posted:Good code is simple and straightforward, and therefore utterly boring.
|
# ? Jun 15, 2012 17:06 |
|
Perhaps more importantly, most pieces of code that are good and short are uninteresting. A few lines of code that does something neat is most likely clever, and therefore by many standards no longer good, as such approaches are no longer easy to understand at a glance or maintain. (Also more practically speaking, presenting a chunk of code you consider perfect to a forum of programmers who can and will pick anything apart is sort of leaning into a punch.)
|
# ? Jun 15, 2012 17:31 |
|
It's like anything, whether it's music, or movies, or literature. Agreeing on what is good is impossible. Agreeing on what is terrible is way easier.
|
# ? Jun 15, 2012 18:08 |
|
I wasn't thinking about code snippets, but more larger projects which are cleanly organized and relatively easy to understand.
|
# ? Jun 15, 2012 20:25 |
|
ymgve posted:I wasn't thinking about code snippets, but more larger projects which are cleanly organized and relatively easy to understand. If you'd like to look at a well written C codebase, I'd highly recommend SQLite. drh is a really good programmer and it shows.
|
# ? Jun 15, 2012 20:41 |
|
Honestly you'd probably get more mileage out of a "Code that you know in practice is terrible but still makes you go " thread.
|
# ? Jun 16, 2012 02:47 |
|
That could be pretty interesting, actually.
|
# ? Jun 16, 2012 03:56 |
|
ymgve posted:I wasn't thinking about code snippets, but more larger projects which are cleanly organized and relatively easy to understand. I tend to find code beautiful in theory and rarely in practice. Code can only be as beautiful as the problem it solves, and most of the problems we face are ugly.
|
# ? Jun 16, 2012 03:59 |
|
Plorkyeran posted:That could be pretty interesting, actually. Isn't that the screenshot thread
|
# ? Jun 16, 2012 04:00 |
|
tef posted:I tend to find code beautiful in theory and rarely in practice. Code can only be as beautiful as the problem it solves, and most of the problems we face are ugly. That's why I was tempted to cite jQuery as an example of good code, even though the code itself isn't beautiful. It provides an elegant interface that solves difficult problems, which is often way more important than the underlying implementation.
|
# ? Jun 16, 2012 05:37 |
|
Courtesy of reddit:code:
|
# ? Jun 16, 2012 05:38 |
|
Yeah, that's an SGML-ism that became an issue to some web standards spergs when XHTML self-closing tags came about.
|
# ? Jun 16, 2012 08:16 |
|
1337JiveTurkey posted:Honestly you'd probably get more mileage out of a "Code that you know in practice is terrible but still makes you go " thread. code:
|
# ? Jun 16, 2012 09:46 |
|
php:<? $programCount = count($programs); $column1Count = $column2Count = $column3Count = 0; if ($programCount%3) $column3Count = - 2 + $column1Count = $column2Count = round($programCount / 3) + 1; if (!($programCount%3)) $column1Count = $column2Count = $column3Count = $programCount / 3; ?>
|
# ? Jun 16, 2012 12:07 |
|
1337JiveTurkey posted:Honestly you'd probably get more mileage out of a "Code that you know in practice is terrible but still makes you go " thread. Actually I do happen to think that the Linux kernel is a good example of good code, from what I've seen of it. It's very unpretentious, the only "best practices" approach it takes being an undogmatic "write what you mean."
|
# ? Jun 16, 2012 13:18 |
|
DaTroof posted:That's why I was tempted to cite jQuery as an example of good code, even though the code itself isn't beautiful. It provides an elegant interface that solves difficult problems, which is often way more important than the underlying implementation. I think my favourite piece of code is this polyglot quine code:
|
# ? Jun 16, 2012 15:40 |
|
ymgve posted:To derail a little bit, what are some examples of really good code?
|
# ? Jun 16, 2012 17:38 |
|
PrBacterio posted:Actually I do happen to think that the Linux kernel is a good example of good code, from what I've seen of it. It's very unpretentious, the only "best practices" approach it takes being an undogmatic "write what you mean." code:
|
# ? Jun 16, 2012 18:01 |
|
Mustach posted:And then you get things like What the hell. Also, what gcc flag did it inspire?
|
# ? Jun 16, 2012 21:40 |
|
KaneTW posted:What the hell. -fdelete-null-pointer-checks Assume that programs cannot safely dereference null pointers, and that no code or data element resides there. This enables simple constant folding optimizations at all optimization levels. In addition, other optimization passes in GCC use this flag to control global dataflow analyses that eliminate useless checks for null pointers; these assume that if a pointer is checked after it has already been dereferenced, it cannot be null. Note however that in some environments this assumption is not true. Use -fno-delete-null-pointer-checks to disable this optimization for programs that depend on that behavior. Some targets, especially embedded ones, disable this option at all levels. Otherwise it is enabled at all levels: -O0, -O1, -O2, -O3, -Os. Passes that use the information are enabled independently at different optimization levels
|
# ? Jun 16, 2012 21:54 |
|
Would you be sure that something in blah() didn't set p to NULL after it had already been dereferenced, directly or indirectly? Aliasing and mutable variables are a pain~
|
# ? Jun 16, 2012 23:17 |
Vanadium posted:Would you be sure that something in blah() didn't set p to NULL after it had already been dereferenced, directly or indirectly? Aliasing and mutable variables are a pain~ C++ code:
Now, this on the other hand would be a completely different matter: C++ code:
|
|
# ? Jun 16, 2012 23:31 |
|
code:
|
# ? Jun 16, 2012 23:55 |
|
The original kernel bug was something likecode:
|
# ? Jun 17, 2012 00:03 |
|
Note that this was a kernel bug that was fixed, but that gcc a) didn't warn about the check-after-dereference and b) deleting the check-after-dereference turned it from a logic error into a local root exploit.
|
# ? Jun 17, 2012 06:00 |
|
pseudorandom name posted:Note that this was a kernel bug that was fixed, but that gcc a) didn't warn about the check-after-dereference and b) deleting the check-after-dereference turned it from a logic error into a local root exploit. To be fair to GCC, this is a case where the C spec explicitly permits demons to fly out your nose. See http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html for why this sort of thing is baked into C.
|
# ? Jun 17, 2012 20:17 |
|
|
# ? May 21, 2024 02:16 |
|
There's a qualitative difference between narrowly following the spec and providing a useful tool, and a knee-jerk response of "But the spec allows us to do this!" doesn't ingratiate you with your users. edit: And to their credit in this case, they did add that compiler switch. pseudorandom name fucked around with this message at 20:48 on Jun 17, 2012 |
# ? Jun 17, 2012 20:30 |