|
floWenoL posted:Oh, how cute, it's someone who hasn't ever needed to program for performance! Never found I could do much better than just telling gcc to do a profiled build. Unless I did it in asm. If you're playing guess-what-the-compiler-will-do you're wasting time.
|
# ? Dec 24, 2008 15:04 |
|
|
# ? May 15, 2024 03:33 |
|
Zombywuf posted:If you're playing guess-what-the-compiler-will-do you're wasting time. Optimizing SQL is fun, eh ? Context: This is the code zombywuf normally optimizes for performance, and most of that is nearly all guessing what the compiler will do (in a non-deterministic way) tef fucked around with this message at 16:06 on Dec 24, 2008 |
# ? Dec 24, 2008 16:03 |
|
Zombywuf posted:Never found I could do much better than just telling gcc to do a profiled build. Unless I did it in asm. If you're playing guess-what-the-compiler-will-do you're wasting time. There's a difference between second-guessing the compiler and making your code amenable to optimization. A compiler (even with profile-driven optimization) is a tool, not an oracle, and dropping down to writing assembly, even when possible, is a dumb move if it's not a last resort.
|
# ? Dec 25, 2008 03:33 |
|
tripwire posted:Ulillillia released the source code for a program he designed in C which converts the sampling rate of PCM wave files. As a DSP guy, the concept of a lookup table (especially repeating similar fractions over and over) for this leaves me speechless.
|
# ? Dec 26, 2008 02:41 |
|
SporkOfTruth posted:Oh my god. Oh....my god. He could have googled "sample rate conversion" and found something better. He's autistic
|
# ? Dec 26, 2008 18:52 |
|
Sewer Adventure posted:He's autistic Proof that being autistic doesn't mean you're some sort of savant.
|
# ? Dec 27, 2008 01:06 |
|
Mikey-San posted:why
|
# ? Dec 28, 2008 16:20 |
|
Rottbott posted:It was poorly desgined to begin with, then maintained and added to over many years by bad programmers. There are also hundreds of global variables, many of which have incorrect hungarian prefixes where the type has been changed but not the variable name. God I hate hungarian notation. How in the hell did anyone ever think it was a smart idea
|
# ? Dec 28, 2008 23:43 |
|
tripwire posted:God I hate hungarian notation. How in the hell did anyone ever think it was a smart idea Ask nebby!
|
# ? Dec 29, 2008 01:23 |
|
tripwire posted:God I hate hungarian notation. How in the hell did anyone ever think it was a smart idea Its original intent - to document the purpose and usage of the variable - was a great idea. Somehow it got perverted into being only the type, which is obviously useless.
|
# ? Dec 29, 2008 04:45 |
|
Steampunk Mario posted:Its original intent - to document the purpose and usage of the variable - was a great idea. Somehow it got perverted into being only the type, which is obviously useless. At the risk of opening a can of worms, its retarded in either form. You are only adding more headaches for yourself later on.
|
# ? Dec 29, 2008 06:25 |
|
tripwire posted:At the risk of opening a can of worms, its retarded in either form. You are only adding more headaches for yourself later on. I'm not some hungarian evangelist - I'm just saying its current usage is unambiguously worthless, but its original intent had potential to make more readable, self-documenting code. Not that it matters since most of us don't get to decide on the coding style for our particular codebase anyway.
|
# ? Dec 29, 2008 06:30 |
|
Steampunk Mario posted:I'm not some hungarian evangelist - I'm just saying its current usage is unambiguously worthless, but its original intent had potential to make more readable, self-documenting code. Not that it matters since most of us don't get to decide on the coding style for our particular codebase anyway. "Purpose and usage" of a variable are a kind of typing; even if the compiler doesn't enforce them, typedefs and the like are a better way to encode that information than naming conventions. Hungarian notation sort of vaguely makes sense if you are stuck with a type system less adequate than C's and don't even have something like a preprocessor available; even then, I would advise changing toolchains or supplying descriptive comments at variable declarations instead.
|
# ? Dec 29, 2008 07:31 |
|
ShoulderDaemon posted:"Purpose and usage" of a variable are a kind of typing; even if the compiler doesn't enforce them, typedefs and the like are a better way to encode that information than naming conventions. Hungarian notation sort of vaguely makes sense if you are stuck with a type system less adequate than C's and don't even have something like a preprocessor available; even then, I would advise changing toolchains or supplying descriptive comments at variable declarations instead. Hungarian notation isn't anything more than a standardized method of encoding information about a variable into its name. This is something that is always done when a variable name is created, standardizing it isn't intrinsically bad. Though most people's usages of Hungarian notation is very bad. twodot fucked around with this message at 09:04 on Dec 29, 2008 |
# ? Dec 29, 2008 08:56 |
|
twodot posted:Hungarian notation isn't anything more than a standardized method of encoding information about a variable into its name. This is something that is always done when a variable name is created, standardizing it isn't intrinsically bad. Types aren't anything more than a method of encoding information about a variable in the same place the variable is created. They have many advantages over name-based methods: they are easier for tools to parse and reason about, many languages feature some form of checking that expressions are made of compatible types, many compilers are able to use them to decide on optimal storage representations, and you don't have to retype them over and over whenever you use the variable. But we're getting way afield of the topic of the thread; if someone wants to debate this more, maybe they should start another "hungarian notation isn't that bad really" thread for it.
|
# ? Dec 29, 2008 09:07 |
|
ShoulderDaemon posted:Types aren't anything more than a method of encoding information about a variable in the same place the variable is created. They have many advantages over name-based methods: they are easier for tools to parse and reason about, many languages feature some form of checking that expressions are made of compatible types, many compilers are able to use them to decide on optimal storage representations, and you don't have to retype them over and over whenever you use the variable.
|
# ? Dec 29, 2008 09:11 |
|
twodot posted:If a static tool can take advantage of the information absolutely put it into the type, if a person can take advanatage of the information, it may be better off in the name. However, redundancy between the two should be minimized. As long as the information's available in the type, then the IDE should be able to provide it to the user in a variety of ways without needlessly complicating the naming scheme used for variables. You could even have it display in-line ghostly (light-gray inactive text) Hungarian type prefixes to all the variables for users who want the Hungarian look. That being said, I realize that it's easy to pass the buck to the IDE when such a feature may not actually exist.
|
# ? Dec 29, 2008 17:35 |
|
tripwire posted:God I hate hungarian notation. How in the hell did anyone ever think it was a smart idea Maybe this is my own crackpot theory, but I blame Fortran. First a brief history lesson. The oldest versions of the language didn't have a way to declare variables. In Fortran I (mid to late 1950s), you had 26 variables corresponding to the 26 letters of the alphabet. The type of the variable was determined based on the letter used. I, J, K, L, M, and N were integers, with all others floating point. In Fortran IV (early 1960s, standardized as Fortran 66), support was added for explicit type declaration. However it still supported implicit typing. If at the beginning of a subroutine you had "IMPLICIT INTEGER (I-N)", then you were saying that any variable starting with letters I-N was an integer. This led to conventions, particularly prevalent in Fortran IV and 77 code, that integers would be started with the letters I-N whether they were explicitly declared or not. My suspicion is that the older programmers, used to the old way of things, continued to prefix their variables, and they were likely also the ones to write documentation, and of course then newer programmers mimicked their style, keeping the tradition going. While I haven't seen it, based on my experience with old Fortran code and some documentation, I wouldn't be surprised to see a few paragraphs in old books recommending the practice of adding a letter to the variable name to make the code clearer. Now we are too my crackpot theory. I believe that Charles Simonyi originally learned to program in Fortran and would have known all of the above, or at least enough of it to follow the practice of adding a prefix to a variable. This is reasonable because he worked at Xerox PARC from 1972-1981, according to Wikipedia. Fortran was one of the main languages of that era. I also believe that Simonyi carried this convention with him to Microsoft and the Excel team. Most likely after another programmer on one of the teams at Microsoft questioned Simonyi on his naming conventions, he became defensive (as programmers tend to be), and rationalized the whole system as a means to making code easier to read and using the convenient first name/last name switch of his native Hungary as the last piece in the puzzle.
|
# ? Dec 29, 2008 18:34 |
|
6174 posted:Maybe this is my own crackpot theory That has no relation to reality at all. Wikipedia posted:In Systems Hungarian notation, the prefix encodes the actual data type of the variable. For example: Charles Simonyi's original paper proposed what is now know as "Apps Hungarian", which adds semantic information about how the variable is used. Even if you dislike the idea of this, it should be pretty obvious why someone would consider it a good idea. However, he unfortunately used the word "type" for this, which resulted in people misinterpreting what he meant, resulting in the awful "Systems Hungarian" used for all of the Win32 stuff.
|
# ? Dec 30, 2008 18:00 |
|
twodot posted:This is kind of bizarre in my opinion. With a sufficiently strong type system you can claim any information is part of the typing. There are trade offs involved with deciding what information you put into a typedef and what information you put into a variable name. Personally, I think it can be useful to put information like whether a variable counts characters or bytes into the variable name rather than as a comment in the variable declaration or as a named type. Jumping between usages and definitions has costs especially in more object oriented code where definitions are non-local.
|
# ? Dec 30, 2008 19:03 |
|
Plorkyeran posted:That has no relation to reality at all. Whether Simonyi's original paper proposed Apps Hungarian or Systems Hungarian neither proves nor refutes my potential theory (which I freely admit could be wrong). However, if you actually read what MSDN claims is a reprint of the paper, you'll see that in Table 4, is a listing of "common primitive types" which would now be known as Systems Hungarian. In fact the section of the Wikipedia article you blithely copied gives an example of a Systems Hungarian prefix as sz and states it is from the original paper (it is in Table 4). This suggests that the lack of clarity in his paper comes from more than just the usage of the word "type".
|
# ? Dec 31, 2008 03:28 |
|
Oh variable naming. It's an art in and of itself:php:<? $the_ID = $_GET['ID']*1; $kill_me_now = get_magic_quotes_gpc(); ... ... ... mysql_query("UPDATE `users_table` SET `name`='".mysql_escape_string(($kill_me_now?stripslashes($name):$name))."' WHERE `ID`=".$the_ID); ?>
|
# ? Dec 31, 2008 16:09 |
|
Kharya posted:Oh variable naming. It's an art in and of itself: php 4.2.0 seems oddly appropriate for this code
|
# ? Dec 31, 2008 17:15 |
|
Kharya posted:Oh variable naming. It's an art in and of itself: Why is your dev server running different versions of stuff than your live server?
|
# ? Jan 1, 2009 00:41 |
|
awesmoe posted:Why is your dev server running different versions of stuff than your live server?
|
# ? Jan 1, 2009 03:48 |
|
code:
|
# ? Jan 1, 2009 07:15 |
|
Factor Mystic posted:
Edit: Holy poo poo, it is. That'll teach me to joke about such things. zootm fucked around with this message at 14:26 on Jan 1, 2009 |
# ? Jan 1, 2009 13:57 |
|
Yep Lucky for them, it only killed it for a day.
|
# ? Jan 1, 2009 19:20 |
|
code:
|
# ? Jan 1, 2009 20:55 |
|
Factor Mystic posted:
It took me a while to notice the problem with that code. I kept thinking "Well, it looks reasonable..." Edge-case bugs suck, but you'd think they would have done some testing of the leap-year handling code before release.
|
# ? Jan 1, 2009 21:01 |
|
mr_jim posted:It took me a while to notice the problem with that code. I kept thinking "Well, it looks reasonable... I kept trying to figure out how it would arrive at a wrong answer and could not come up with anything.
|
# ? Jan 1, 2009 21:04 |
|
Vanadium posted:I kept trying to figure out how it would arrive at a wrong answer and could not come up with anything. If you're still curious, the error occurs when days == 366, as in New Years Eve on a leap year. The "if (days > 366)" statement doesn't get executed, so days never gets decremented. But the condition for the while loop (days > 365) is still true, so an infinite loop occurs. It's a piece of code that looks ok at first glance, but it's really a time bomb. Luckily, in this case, it just caused minor inconvenience.
|
# ? Jan 1, 2009 21:25 |
|
I ended up realising that I was looking for the wrong thing, yeah.
|
# ? Jan 1, 2009 21:42 |
|
Dan Two Hundred posted:
That's painful to read. Less hotshot superstar, more lines of code please.
|
# ? Jan 1, 2009 22:51 |
|
It's also incorrect .
|
# ? Jan 1, 2009 22:52 |
|
A while back after John McCain nominated Sarah Palin as his running mate, my company (Palin's ISP) had me make some super-fast emergency security upgrades to our ticket system to make sure none of our help desk techs were doing anything naughty to her account, and also a few other major ones. Anyway, they wanted the changes done yesterday so I whipped up this ugly bit of code in the accounts perl module: code:
|
# ? Jan 1, 2009 23:19 |
|
I guess you could have used a switch but no code with arbitrary numbers like that is going to be nice.
|
# ? Jan 2, 2009 11:00 |
|
awesmoe posted:Why is your dev server running different versions of stuff than your live server? This is the real coding horror, along with not using prepared statements.
|
# ? Jan 2, 2009 17:40 |
|
MasterSlowPoke posted:I guess you could have used a switch but no code with arbitrary numbers like that is going to be nice. Throw them into a data structure, and you can make it look a little nicer: code:
And ideally, when there's some free time, you could move it to a proper configuration file that's read by the program. But there's always that sense of "Well, it works so why mess with it?"
|
# ? Jan 2, 2009 20:10 |
|
|
# ? May 15, 2024 03:33 |
|
comaerror posted:
You should be really proud of your var naming, though. $fireme is genius.
|
# ? Jan 3, 2009 00:42 |