|
Cross_ posted:Ignoring the fact that this betrays bad design- you have to change the type declaration anyway what's the problem with doing search&replace at the same time? Hungarian notation is an old technique that has no place in modern C++ programming, but there are one or two odd exceptions which are either genuinely useful, or are a strange hang-over. The scope of variables is of critical importance in C++, and in OO programming in general. As such, you often see 'g_', 's_' and 'm_' prefixes used widely - or similar conventions for distinguishing member variables. The 'p_' prefix is more of a comfort thing. There's not necessarily any reason why it should be used, but it's a fairly firmly entrenched an widely used habit. It generally doesn't cause as many problems as other types of type prefix though. One of the main arguments against Hungarian is that if you change the type, then you have to hunt out and change everywhere the variable is used for no good reason. Whereas if you change a variable to or from a pointer type, then you will generally have to change all of the places where it's being used anyway, so the negative impact of this particular prefix is relatively light. I've not seen 'r' being used all that often, and I suspect it's a dirty Java habit
|
# ? Oct 2, 2008 23:41 |
|
|
# ? May 15, 2024 02:03 |
|
Vanadium posted:So would you prefix a smart pointer object variable with p? I'd prefix it with sp, which is actually quite useful because if you're using a smart pointer implementation that makes them fairly transparent related to regular pointers, it can be quite useful to track which is which. e: and unlike most other cases of hungarian notation in C, is not made obsolete by strong typing.
|
# ? Oct 2, 2008 23:58 |
|
Cross_ posted:Ignoring the fact that this betrays bad design- you have to change the type declaration anyway what's the problem with doing search&replace at the same time? Yeah, I've never seen badly designed software that uses Hungarian notation. People make bad software, and Hungarian notation makes it worse when they do. Persuading people to drop it is step one because it's much easier than teaching good design.
|
# ? Oct 3, 2008 00:10 |
|
JoeNotCharles posted:The difference between an unsigned integer and a signed integer is often accidental - if you just automatically make an int, but you know it'll never get a value less than 0, you might want to change it to an unsigned int later to get more range. No you don't.
|
# ? Oct 3, 2008 09:43 |
|
JoeNotCharles posted:if you just automatically make an int, but you know it'll never get a value less than 0, you might want to change it to an unsigned int later to get more range. never is a strong word
|
# ? Oct 3, 2008 09:48 |
|
My favourite coding horror side effect of Hungarian notation is little gems like this scattered around here and there:code:
|
# ? Oct 3, 2008 11:29 |
|
floWenoL posted:No you don't. That makes no grammatical sense. There's no clause in what I said that can be negated with "don't", because they're all qualified. HAH! NOW I AM PEDANT!
|
# ? Oct 3, 2008 14:52 |
|
JoeNotCharles posted:That makes no grammatical sense. There's no clause in what I said that can be negated with "don't", because they're all qualified. is not
|
# ? Oct 3, 2008 15:47 |
|
TSDK posted:My favourite coding horror side effect of Hungarian notation is little gems like this scattered around here and there: code:
Edit: Missing code tag.
|
# ? Oct 3, 2008 16:01 |
|
JediGandalf posted:Probably not exactly hungarian notation but it's along the same lines. I present you our old table and column naming scheme.
|
# ? Oct 3, 2008 16:50 |
|
TSDK posted:Hungarian notation is an old technique that has no place in modern C++ programming, but there are one or two odd exceptions which are either genuinely useful, or are a strange hang-over. Well, not really. It was originally intended to give context to the variable's usage, not type. So you might prefix something with 'idx' or some such to indicate that it's an index, but you wouldn't put the type in the variable name since that's just stupid.
|
# ? Oct 4, 2008 07:35 |
|
Steampunk Mario posted:So you might prefix something with 'idx' or some such to indicate that it's an index The only reason that isn't type information is because languages like C don't have strong typing on typedefs. Being able to do typedef unsigned int index_t; typedef unsigned int age_t; and have the compiler warn when you use an index_t where it expects an age_t would completely remove even that flimsy justification for Hungarian notation, as you would encode all of your "usage context" in the type system where it belongs.
|
# ? Oct 4, 2008 07:54 |
|
ShoulderDaemon posted:The only reason that isn't type information is because languages like C don't have strong typing on typedefs. Being able to do typedef unsigned int index_t; typedef unsigned int age_t; and have the compiler warn when you use an index_t where it expects an age_t would completely remove even that flimsy justification for Hungarian notation, as you would encode all of your "usage context" in the type system where it belongs. You can do this in C++, but it's an enormous pain in the rear end because you have to hand-code every operation you want to provide, even those which seem to be logically derivable from others. Haskell makes that substantially easier, but converting between types is still a pain in the rear end. But yes, a shop that demands Hungarian notation would generally be better off demanding the consistent use of type-safe wrapping types.
|
# ? Oct 4, 2008 09:11 |
|
rjmccall posted:Haskell makes that substantially easier, but converting between types is still a pain in the rear end. I've never found converting between types in Haskell to be very painful - I just pattern match to get at the contained type I care about, or make my newtypes instances of the typeclasses I care about. But we're getting off-topic here. To contribute, I'm dealing with code generated by automated proof systems that is sort of painful. Here's a short example, the extracted definition of sum over a list of natural numbers: code:
code:
code:
I'm sure all these layers of indirection represent something useful within the context of the proof-checker, but when the code it's spitting out is so far removed from what any human would write even on simple examples like this, it's very hard to correctly use extracted code on complicated models, where it would be most useful.
|
# ? Oct 4, 2008 09:46 |
|
ShoulderDaemon posted:I've never found converting between types in Haskell to be very painful - I just pattern match to get at the contained type I care about, or make my newtypes instances of the typeclasses I care about. It's certainly much better than C++, but you and I seem to have different attitudes about obnoxiousness --- I think having to introduce little function calls everywhere is annoying. I fully understand why I have to do it, I just think it's annoying. ShoulderDaemon posted:I'm sure all these layers of indirection represent something useful within the context of the proof-checker, but when the code it's spitting out is so far removed from what any human would write even on simple examples like this, it's very hard to correctly use extracted code on complicated models, where it would be most useful. If you're curious, list_rect is the axiom of structural induction for lists, derived from the structure of the type declaration. list_rec is probably there to catch some corner case in the code generation which doesn't happen to arise with this type --- possibly something with higher-rank polymorphism. Also, while I agree that the code is far from what a human would write, I don't understand why it's any more difficult to use: the sum function, which is what you actually extracted, is called in exactly the usual manner.
|
# ? Oct 4, 2008 11:02 |
|
rjmccall posted:You can do this in C++, but it's an enormous pain in the rear end because you have to hand-code every operation you want to provide, even those which seem to be logically derivable from others. Haskell makes that substantially easier, but converting between types is still a pain in the rear end. Shouldn't there really be an easy way to do this? Like code:
|
# ? Oct 4, 2008 15:37 |
|
Steampunk Mario posted:Well, not really. It was originally intended to give context to the variable's usage, not type. So you might prefix something with 'idx' or some such to indicate that it's an index, but you wouldn't put the type in the variable name since that's just stupid. code:
|
# ? Oct 6, 2008 14:29 |
|
Mick posted:I found this a few years back. Treat warnings as errors is the best thing ever.
|
# ? Oct 7, 2008 00:48 |
|
Evis posted:Treat warnings as errors is the best thing ever. Speaking of which, I'm cleaning up warnings right now: code:
How do you get int confused with FILE * and not notice? EDIT: I was so annoyed that this idiot used "fopen" instead of "open" that I posted immediately. I just realized what this code actually <i>does</i>. Christ, that's even worse! JoeNotCharles fucked around with this message at 01:59 on Oct 7, 2008 |
# ? Oct 7, 2008 01:56 |
|
JoeNotCharles posted:How do you get int confused with FILE * and not notice? Well, if he is calling it like FILE* f = open("foo", O_RDONLY); and not getting a warning for that conversion either, the whole thing might just work!
|
# ? Oct 7, 2008 02:25 |
|
Vanadium posted:Well, if he is calling it like FILE* f = open("foo", O_RDONLY); and not getting a warning for that conversion either, the whole thing might just work! Actually, what it's doing is implementing open(), read() and write() on Windows CE (which lacks them, I guess?) in terms of fopen(), fread() and fwrite(). code:
|
# ? Oct 7, 2008 03:37 |
|
JoeNotCharles posted:
Only on 32-bit machines... e: Also true. My mistake. narbsy fucked around with this message at 04:00 on Oct 7, 2008 |
# ? Oct 7, 2008 03:56 |
|
narbsy posted:Only on 32-bit machines... I'm not aware of any 64-bit machines running Windows CE...
|
# ? Oct 7, 2008 03:59 |
|
JoeNotCharles posted:I'm not aware of any 64-bit machines running Windows CE...
|
# ? Oct 7, 2008 12:03 |
|
StickGuy posted:Yeah, man, no one will be using this program in the year 2000. #define int __int64 will solve all these problems
|
# ? Oct 8, 2008 00:26 |
|
I'm not a great programmer, but at least I know enough to not do this:code:
|
# ? Oct 8, 2008 20:53 |
|
I need to test if this number is odd. Think man, think! Hey isn't there something about odd numbers and dividing by two that I learned in kindergarten? <A couple of hours later, after three of four pages of scratch work> Oh hey, look at this, whenever I divide an odd number by 2 I get .5 on the end... regex to the rescue!
|
# ? Oct 8, 2008 21:43 |
|
Roseo posted:I'm not a great programmer, but at least I know enough to not do this: code:
Who wants to go golfing?
|
# ? Oct 8, 2008 22:01 |
|
ashgromnies posted:
Instead of doing a modulus, just keep making $n = !$n after the assignment.
|
# ? Oct 8, 2008 23:19 |
|
The int/FILE* conversion did not jump out at me and shouldn't be a problem with WinMobile at all. On the other hand I am wondering about all the possible values that an uninitialized mode[1] might contain.
|
# ? Oct 9, 2008 00:00 |
|
TRex EaterofCars posted:Instead of doing a modulus, just keep making $n = !$n after the assignment. gently caress not. code:
|
# ? Oct 9, 2008 00:10 |
|
Cross_ posted:The int/FILE* conversion did not jump out at me and shouldn't be a problem with WinMobile at all. On the other hand I am wondering about all the possible values that an uninitialized mode[1] might contain. Hey, good catch - I'll make sure to fix that while I'm there.
|
# ? Oct 9, 2008 04:54 |
|
TRex EaterofCars posted:Instead of doing a modulus, just keep making $n = !$n after the assignment. Well, $n's also used to number the table, so it needs to stay as being incremented by 1 each time through the loop. I just set $color to equal 0xFF0000 + (0xCC99 * ($n % 2)), and stuck 'color="#<?php echo $color ?>"' into the HTML. It's not the cleanest code out there. But it's a drat sight better than regexing the loving thing to figure out if the line is odd or even. Edit: Argh, that's not right. 0xFFFFFF - (0x3366 * ($n % 2) I think is what I did. Roseo fucked around with this message at 05:42 on Oct 9, 2008 |
# ? Oct 9, 2008 05:32 |
|
php:<? function returnshow (){ global $_SESSION, $godlyness, $exequeries_1__,$return; $this->canshow = true; if (!$this->directory AND $this->root_dir){ $this->directory($this->root_dir); } if (!is_dir($this->directory)){ $this->canshow(false); $this->error_message($this->message_nodir); } if ($this->mode == "gallery"){ $this->lockfolder(false); $this->radio_name("settings_avatarchange_copy_file"); $this->hide_icons(true); } elseif ($this->mode == "attachments_show"){ $this->lockfolder(true); $this->radio_name(false); } elseif ($this->mode == "attachments_edit"){ $this->lockfolder(true); $this->radio_name(false); } if (!substr($this->directory,0,strlen($this->root_dir)) == $this->root_dir){ $this->canshow(false); $this->error_message("Out of root dir: ".$this->directory.", ".$this->root_dir); } if ($this->canshow == true){ $scanned_files = scandir($this->directory); $return_code .= "<table border=\"0\" width=\"75%\">"; $return_code .= "<tr><td></td><td colspan=\"3\">".(substr($this->directory,strlen($this->root_dir)))."</td></tr>"; if ($this->lockfolder == false AND strlen($this->directory) > strlen($this->root_dir) AND substr($this->directory,0,strlen($this->root_dir)) == $this->root_dir){ $return_code .= "<tr><td valign=\"middle\"><a href=\"forums.php?roomA=gallery&change_dir=". $dir."/..\">"."<img src=\"images/folder_up.gif\" align=\"middle\" border=\"0\" width=\"32\" ". "height=\"32\"></a></td><td colspan=\"3\"><a href=\"forums.php?roomA=gallery&change_dir=". $this->directory."/..\">Up a level"."</a></td></tr>"; } if (empty($this->ext_filter)){ $this->ext_filter = ".*"; } $fi = 0; foreach($scanned_files as $file){ if (preg_match("/(".$this->ext_filter.")/i",substr($file,strlen($file)-4,4)) AND $file != "." AND $file != ".."){ $fi++; $return_code_sub .= "<tr><td valign=\"middle\">"; if ($this->mode == "attachment_view"){ $str_a = "<a href=\"".$this->directory."/".$file."\" target=\"_blank\">"; $str_b = "</a>"; } else { $str_a = ""; $str_b = ""; } if (!$this->hide_icons) { $return_code_sub .= $str_a.file_icon_image($file).$str_b; } $return_code_sub .= "</td><td width=\"98%\">" . $str_a.$file.$str_b . "<br>" . format_filesize(filesize($this->directory . "/" . $file)) . ".</td>"; if ($this->mode == "gallery"){ $return_code_sub .= "<td>".avatar_image($file,($this->directory."/"))."</td>"; } $return_code_sub .= "\n"; if ($this->radio_name AND !($this->select_name)){ $return_code_sub .= "<td><input name=\"settings_avatarchange_copy_file\" type=\"radio\" value=\"". $this->directory."/".$file."\"></td><td>"; } if ($this->select_name AND !($this->radio_name)){ $return_code_sub .= "<td><input type=\"checkbox\" name=\"". substr($this->select_name,0,strlen($this->select_name))."\" value=\"$file\">"; } // attached_file_do[] } elseif (is_dir($this->directory."/".$file) AND (substr($file,0,1) != ".")){ $avatar_dir_output .= "<tr><td><a href=\"forums.php?roomA=gallery&change_dir=". $this->directory."/".$file."\">". "<img align=\"middle\" src=\"images/folder.gif\" border=\"0\" width=\"32\" height=\"32\">". "</a></td><td><a href=\"forums.php?roomA=gallery&change_dir=". $this->directory."/".$file."\">".$file."</a></td></tr>\n"; } } // end of foreach // Select all checkbox if ($this->select_name AND !($this->radio_name) AND $fi > 1){ $return_code .= "<tr><td colspan=\"2\"></td><td>". "<input type=\"checkbox\" name=\"CheckAll\" value=\"Check All\" ". "onChange=\"UcheckAll(document.workform1['attached_file_do[]'],this.checked)\"></td></tr>"; } if ($this->mode == "gallery" AND (is_file($this->directory."/info.txt") OR is_file($this->directory."/credits.txt") )){ $info = file_get_contents($this->directory."/info.txt"); $return_code .= "<tr><td></td><td colspan=\"3\">Info: <font face=\"courier\">".$info."</font></td></tr>"; unset($info);} $return_code .= $avatar_dir_output.$return_code_sub; if ($this->mode == "attachment_edit"){ if ($fi == 0){ $return_code .= "<tr><td colspan=\"2\">There are currently no attached files.</td></tr>"; } $return_code .= "<tr><td colspan=\"2\"><select name=\"attach_select\">"; $return_code .= "<option value=\"nothing\">-- Select --</option>"; if ($fi > 0) { $return_code .= "<option value=\"removeattach\">Remove</option>"; } $return_code .= "<option value=\"removeallattach\">Remove All</option>"; $return_code .= "</select></td><td align=\"right\"><input type=\"submit\" name=\"AttachFilesDo\" value=\"Do\"></td></tr>"; } if ($this->mode == "gallery" AND !empty($return_code_sub)){ $return_code .= "<tr><td colspan=\"2\" align=\"center\"><p>". "<input type=\"submit\" name=\"Set Avatar\" value=\"Set Avatar\"></td></tr>"; } $return_code .= "</table>"; return $return_code; unset($return_code); } else { $return_code .= $this->error_message; return $return_code; unset($return_code); } } ?>
|
# ? Oct 12, 2008 00:08 |
|
I was looking through some old code for a 'project' I was doing to try to teach myself OpenGL about six years ago, and I came across a few horrors:code:
I think I knew they existed but couldn't figure out how to make it work. Whoops. I can't even figure out what the hell the top comment was supposed to mean. Also this absolute horror that was the cActor:: Draw() function. code:
I don't even know what the gently caress I was doing with 'ROT_ORDER'. Must have seemed like a good idea at the time, though. I stopped working on this about the time I couldn't figure out how to make the 'car' tilt with the ground properly. ODE, what's that? And poo poo like this was littered through the 'code'. code:
|
# ? Oct 14, 2008 09:34 |
|
I just found this gem when testing a newsletter for a client, who was wondering why the system was sending newletter previews successfully, but they never got any.code:
|
# ? Oct 31, 2008 13:45 |
|
Sartak posted:gently caress not. Doesn't work on PHP 5.2.6 (cli) (built: Jul 17 2008 23:04:49)
|
# ? Nov 1, 2008 00:01 |
|
Here's one for you Python programmers out there:code:
|
# ? Nov 1, 2008 06:28 |
|
functional posted:Doesn't work on PHP 5.2.6 (cli) (built: Jul 17 2008 23:04:49) Tested only in Perl. v:)v
|
# ? Nov 1, 2008 07:40 |
|
|
# ? May 15, 2024 02:03 |
|
Ok, I'm not an ActionScript programmer and I'm trying to recall this from memory. Bear with me if the syntax isn't exactly correct. You get the idea:code:
code:
Me: *sigh* Let me teach you about concurrency and scope.... Kharya fucked around with this message at 16:29 on Nov 2, 2008 |
# ? Nov 2, 2008 16:26 |