|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On October 27 2014 01:59 Manit0u wrote: I was once working with someone else's code. His variable naming was very helpful and consistent (even more helpful than good names). Every input and output was in the name, so was the variable type (e. g. "s_somestring_in", "i_someint_out", "f_somefloat" - variable with local scope that's neither function param nor is return value etc.). Makes it really easy to follow, the only problem is when you want to change the variable type, as you then have to rename all occurances.
Was nice to work with it since at all times you knew exactly if you're dealing with variable that has been passed to the function, a variable that will be returned or something temporary.
That sounds pretty good ! Does the "s", "i", "f" stands for something in particular ?
|
On October 27 2014 01:59 Manit0u wrote: I was once working with someone else's code. His variable naming was very helpful and consistent (even more helpful than good names). Every input and output was in the name, so was the variable type (e. g. "s_somestring_in", "i_someint_out", "f_somefloat" - variable with local scope that's neither function param nor is return value etc.). Makes it really easy to follow, the only problem is when you want to change the variable type, as you then have to rename all occurances.
Was nice to work with it since at all times you knew exactly if you're dealing with variable that has been passed to the function, a variable that will be returned or something temporary.
I think that's Hungarian notation: http://en.wikipedia.org/wiki/Hungarian_notation
Btw, renaming a variable in a codebase is usually taken care of by your IDE right?
|
On October 27 2014 02:23 Cynry wrote:Show nested quote +On October 27 2014 01:59 Manit0u wrote: I was once working with someone else's code. His variable naming was very helpful and consistent (even more helpful than good names). Every input and output was in the name, so was the variable type (e. g. "s_somestring_in", "i_someint_out", "f_somefloat" - variable with local scope that's neither function param nor is return value etc.). Makes it really easy to follow, the only problem is when you want to change the variable type, as you then have to rename all occurances.
Was nice to work with it since at all times you knew exactly if you're dealing with variable that has been passed to the function, a variable that will be returned or something temporary. That sounds pretty good ! Does the "s", "i", "f" stands for something in particular ?
Hungarian notation - you prefix with the type of the variable - quite useful if you do C or embedded.
uint8_t = ui8<variable name> uint16_t = ui16<variable name> etc...
f is float, d is double, s/str is string.
p if it's a pointer.
Stuff like that. Can make a codebase incredibly ugly if overused.
On October 27 2014 02:34 _fool wrote: Btw, renaming a variable in a codebase is usually taken care of by your IDE right?
If you have a somewhat modern one, yes... Sometimes you're stuck with old ones and the feature might not exist.
|
God I'm dumb today >< s_somestring i_someint f_somefloat....
|
On October 27 2014 02:45 Cynry wrote: God I'm dumb today >< s_somestring i_someint f_somefloat.... For the sake of completeness, nowadays the exact signature of a function is something the IDE should tell you, not the name of the function. I'd advise against hungarian notation.
|
-snip BC your douchiness shouldn't mean i should respond in the same way-
|
i use hungarian but dont do the underscore, can really help sometimes especially if you are tracing numbers which have to stay the same type
Hi everyone, just wandered onto this out of boredom. I used to program in c and c++ with a bit of actionscript now and again. Just recently started to teach python so anymore resources other than the ones on the front page would be great. Such a great language python im finding so far, has all the ability to make some good looking things and gets rid of all that dx and windows code to open a window! problem is, not sure how python does its stuff as im trying to relate it to c++ all time. Im mostly teaching beginners so dont need too much more than what i already know and im mostly using the shell (not pygame) any great resources for pygame would be good, seen a couple of you tube vids and while they are great at programming a game, its too much for newer learners. The second they start goin into rects and all that is where newbies start to get sonfused as they dont know so much about cartesian coords and stuff like that
any way any help is welcome and im quite happy to offer any
|
On October 27 2014 02:37 bangsholt wrote:Show nested quote +On October 27 2014 02:23 Cynry wrote:On October 27 2014 01:59 Manit0u wrote: I was once working with someone else's code. His variable naming was very helpful and consistent (even more helpful than good names). Every input and output was in the name, so was the variable type (e. g. "s_somestring_in", "i_someint_out", "f_somefloat" - variable with local scope that's neither function param nor is return value etc.). Makes it really easy to follow, the only problem is when you want to change the variable type, as you then have to rename all occurances.
Was nice to work with it since at all times you knew exactly if you're dealing with variable that has been passed to the function, a variable that will be returned or something temporary. That sounds pretty good ! Does the "s", "i", "f" stands for something in particular ? Hungarian notation - you prefix with the type of the variable - quite useful if you do C or embedded. uint8_t = ui8<variable name> uint16_t = ui16<variable name> etc... f is float, d is double, s/str is string. p if it's a pointer. Stuff like that. Can make a codebase incredibly ugly if overused. Show nested quote +On October 27 2014 02:34 _fool wrote: Btw, renaming a variable in a codebase is usually taken care of by your IDE right? If you have a somewhat modern one, yes... Sometimes you're stuck with old ones and the feature might not exist.
For this thing I'm mostly stuck with editing through CLI so IDEs are out of the question and the way it works is that it only allows ed server-side. I'm usually doing it via FTP but even then you don't have IDEs for LPC.
Sounds silly but it taught me A LOT.
|
|
|
Hungarian notation is something that should not be used in the way it's actually used in the wild. As Manit0u said, it's a pain to change the type of a variable. Microsoft ran into that a few years back when their API had to change and suddenly there were unsigned int named variables that were signed long ints and such.
Variables should be used in a limited scope so the declaration and use are always close together, which means to know the type you just have to look up (or use your IDE).
We use hungarian notation at work and it's simply annoying and superfluous and there were already instances of $intSomeVariable containing strings and such.
I would recommend reading this blog entry by Joel Spolsky.
|
On October 27 2014 06:14 StatixEx wrote: i use hungarian but dont do the underscore, can really help sometimes especially if you are tracing numbers which have to stay the same type
Hi everyone, just wandered onto this out of boredom. I used to program in c and c++ with a bit of actionscript now and again. Just recently started to teach python so anymore resources other than the ones on the front page would be great. Such a great language python im finding so far, has all the ability to make some good looking things and gets rid of all that dx and windows code to open a window! problem is, not sure how python does its stuff as im trying to relate it to c++ all time. Im mostly teaching beginners so dont need too much more than what i already know and im mostly using the shell (not pygame) any great resources for pygame would be good, seen a couple of you tube vids and while they are great at programming a game, its too much for newer learners. The second they start goin into rects and all that is where newbies start to get sonfused as they dont know so much about cartesian coords and stuff like that
any way any help is welcome and im quite happy to offer any
welcome!
what are you looking at making or learning about? python has something for basically any programmer so it's all up to what you want to tailor your learning towards.
|
On October 27 2014 06:40 Morfildur wrote:Hungarian notation is something that should not be used in the way it's actually used in the wild. As Manit0u said, it's a pain to change the type of a variable. Microsoft ran into that a few years back when their API had to change and suddenly there were unsigned int named variables that were signed long ints and such. Variables should be used in a limited scope so the declaration and use are always close together, which means to know the type you just have to look up (or use your IDE). We use hungarian notation at work and it's simply annoying and superfluous and there were already instances of $intSomeVariable containing strings and such. I would recommend reading this blog entry by Joel Spolsky. Well that is an entirely different definition of hungarian than what I thought, and certainly a much better one.
On October 27 2014 06:34 Nesserev wrote: This might be the dumbest thing that I've heard all month... care to explain yourself a bit more?? As the blog entry above describes nicely, I need to know what the function does/returns, not its type. Especially when it just adds unnecessary clutter. Much like comments that just say the same thing as the code they target.
|
On October 27 2014 07:04 spinesheath wrote:Show nested quote +On October 27 2014 06:40 Morfildur wrote:Hungarian notation is something that should not be used in the way it's actually used in the wild. As Manit0u said, it's a pain to change the type of a variable. Microsoft ran into that a few years back when their API had to change and suddenly there were unsigned int named variables that were signed long ints and such. Variables should be used in a limited scope so the declaration and use are always close together, which means to know the type you just have to look up (or use your IDE). We use hungarian notation at work and it's simply annoying and superfluous and there were already instances of $intSomeVariable containing strings and such. I would recommend reading this blog entry by Joel Spolsky. Well that is an entirely different definition of hungarian than what I thought, and certainly a much better one. Show nested quote +On October 27 2014 06:34 Nesserev wrote: This might be the dumbest thing that I've heard all month... care to explain yourself a bit more?? As the blog entry above describes nicely, I need to know what the function does/returns, not its type. Especially when it just adds unnecessary clutter. Much like comments that just say the same thing as the code they target.
I believe that Nesserv was asking why in the world would you rely on your IDE to tell you that?
|
On October 27 2014 07:31 Manit0u wrote:Show nested quote +On October 27 2014 07:04 spinesheath wrote:On October 27 2014 06:40 Morfildur wrote:Hungarian notation is something that should not be used in the way it's actually used in the wild. As Manit0u said, it's a pain to change the type of a variable. Microsoft ran into that a few years back when their API had to change and suddenly there were unsigned int named variables that were signed long ints and such. Variables should be used in a limited scope so the declaration and use are always close together, which means to know the type you just have to look up (or use your IDE). We use hungarian notation at work and it's simply annoying and superfluous and there were already instances of $intSomeVariable containing strings and such. I would recommend reading this blog entry by Joel Spolsky. Well that is an entirely different definition of hungarian than what I thought, and certainly a much better one. On October 27 2014 06:34 Nesserev wrote: This might be the dumbest thing that I've heard all month... care to explain yourself a bit more?? As the blog entry above describes nicely, I need to know what the function does/returns, not its type. Especially when it just adds unnecessary clutter. Much like comments that just say the same thing as the code they target. I believe that Nesserv was asking why in the world would you rely on your IDE to tell you that? Why wouldn't I? Assuming it's not in the same file, and considering that I certainly don't need the exact signature often enough to make it worth the clutter in the name... Most importantly, I don't need that when I'm just reading the code, say to change or fix it. I want to know what it does, not which types it uses. Code shoud be readable like prose, and I don't think specifying the type of each word in noun prose verb makes noun sense.
|
Specifying the type, not really. But have you read the linked article? Hungarian Notation (apps version) is super useful as it gives you a ton of information about the variable (or function) that no IDE will provide.
|
Well not really, Hungarian Notation isn't really more than a means to write clearer code. If you wrote clearly in the first place and just learned about Hungarian Notation then it hasn't really changed anything. Actually if you use Visual Studio, Eclipse, you get a lot of benefits like being able to provide a summary of the function, and depending on how you would write the summary you get much more benefit from having the IDE than not having it. In other words, I can always supplement Hungarian Notation with an IDE, but you can't display a help tooltip about the function without the IDE, so the IDE's features are almost always a superset of not having an IDE.
|
On October 27 2014 08:09 Manit0u wrote: Specifying the type, not really. But have you read the linked article? Hungarian Notation (apps version) is super useful as it gives you a ton of information about the variable (or function) that no IDE will provide. Yes, as mentioned, I was thinking of the interpretation of hungarian where you specify the type. The one described in the article is a completely different thing and seems perfectly reasonable if used appropriately. I was misled by that common misinterpretation.
That being said, don't underestimate IDEs. IDEs won't display such information so prominently, but stuff like Resharper's Inspect Value Origin will give you a lot of information about variables.
|
|
|
On October 27 2014 06:22 Manit0u wrote:Show nested quote +On October 27 2014 02:37 bangsholt wrote:On October 27 2014 02:23 Cynry wrote:On October 27 2014 01:59 Manit0u wrote: I was once working with someone else's code. His variable naming was very helpful and consistent (even more helpful than good names). Every input and output was in the name, so was the variable type (e. g. "s_somestring_in", "i_someint_out", "f_somefloat" - variable with local scope that's neither function param nor is return value etc.). Makes it really easy to follow, the only problem is when you want to change the variable type, as you then have to rename all occurances.
Was nice to work with it since at all times you knew exactly if you're dealing with variable that has been passed to the function, a variable that will be returned or something temporary. That sounds pretty good ! Does the "s", "i", "f" stands for something in particular ? Hungarian notation - you prefix with the type of the variable - quite useful if you do C or embedded. uint8_t = ui8<variable name> uint16_t = ui16<variable name> etc... f is float, d is double, s/str is string. p if it's a pointer. Stuff like that. Can make a codebase incredibly ugly if overused. On October 27 2014 02:34 _fool wrote: Btw, renaming a variable in a codebase is usually taken care of by your IDE right? If you have a somewhat modern one, yes... Sometimes you're stuck with old ones and the feature might not exist. For this thing I'm mostly stuck with editing through CLI so IDEs are out of the question and the way it works is that it only allows ed server-side. I'm usually doing it via FTP but even then you don't have IDEs for LPC. Sounds silly but it taught me A LOT.
Exactly where hungarian notation makes life so much easier :D
I've been doing something a bit similar, although I could install vim on the machine I remoted into... But that was all. It had vim and clang. Good times :D
|
Whether Hungarian notation is to be advised or not also depends on the language, I do believe. For example you don't want that naming convention is something like Java or C#. In fact, you can look up nearly all coding style guidelines out there on those languages. They specifically strongly advise you against it :D The way to go in those languages is to design your types (classes/interfaces/traits/whatnot) so that they semantically qualify all their variables, and let your IDE help you if you somehow couldn't find out quickly what the type of the object was. Good coding practices however naturally render the types of variables obvious (short methods, stateless functions, good naming etc..)
|
|
|
|
|
|