tag:blogger.com,1999:blog-29331675.post3550723296855822541..comments2024-03-05T17:37:00.995+01:00Comments on The Delphi Geek: Using descriptive variable namesgabr42http://www.blogger.com/profile/06903558857617342477noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-29331675.post-81632972270258244102007-04-21T21:16:00.000+02:002007-04-21T21:16:00.000+02:00Agree. In a way, this is very close to the spirit ...Agree. In a way, this is very close to the spirit of the Hungarian notation.gabr42https://www.blogger.com/profile/06903558857617342477noreply@blogger.comtag:blogger.com,1999:blog-29331675.post-89104307620917437822007-04-21T12:26:00.000+02:002007-04-21T12:26:00.000+02:00Welcome to hungarian notation. (Yes, according to ...Welcome to hungarian notation. (Yes, according to the wikipedia article the original goal of hungarian notation was to actually describe the meaning and usage of a variable rather than its type.)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-29331675.post-13387583218965004872007-04-20T23:08:00.000+02:002007-04-20T23:08:00.000+02:00I love long descriptive names. I hate having to g...I love long descriptive names. I hate having to guess what the hell something does. The units attached to a name is a great idea, makes unit analysis easier for math statements too.<BR/><BR/>Admittedly, many of my for loop variables are just loop, innerloop, that sorta of thing (unless it really, REALLY matters - normally it doesn't... Loop usually does)<BR/><BR/>Something about my code leaves my C programmers in screaming fits. Which seems fair, finding out that an 4 letter variable is actually 16 different variables can be a big motivator for some of my own screaming fits...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-29331675.post-62952526412650780822007-04-20T21:41:00.000+02:002007-04-20T21:41:00.000+02:00Object orientation has its limits - sometime you h...Object orientation has its limits - sometime you have to stop and do something useful.<BR/><BR/>Creating a subtype for every such type is great example of an overkill.gabr42https://www.blogger.com/profile/06903558857617342477noreply@blogger.comtag:blogger.com,1999:blog-29331675.post-26634485924059854402007-04-20T21:37:00.000+02:002007-04-20T21:37:00.000+02:00Using long, postfixed variables is sometimes an in...Using long, postfixed variables is sometimes an indication that the programmer didn't apply object oriented design to his code. For example, you noted that the long names make the following assignment suspicious:<BR/><BR/>someTime := otherTime_UTC<BR/><BR/>While true, a more object oriented approach would be to declare a Time class, and the compiler will take care of all wrong assignments.<BR/><BR/>The same is true in your originalBitrate variable; your post makes it clear that it is a numeric type, an int or a float; but declaring it as its own class would go a long way towards both readability and type-safety.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-29331675.post-25547773841833012762007-04-20T21:04:00.000+02:002007-04-20T21:04:00.000+02:00You could also do something like thisTSpeed_bit_s ...You could also do something like this<BR/><BR/>TSpeed_bit_s = type Double;<BR/>TSpeed_kb_s = type Double;<BR/><BR/>Function To_bit_s(aSpeed : TSpeed_kb_s) : TSpeed_bit_s;<BR/>Function To_kb_s(aSpeed : TSpeed_bit_s) : TSpeed_kb_s;<BR/><BR/>and let the compiler check that you never make the wrong assignment;ajasjahttps://www.blogger.com/profile/10042562102535275012noreply@blogger.comtag:blogger.com,1999:blog-29331675.post-23525293512511132932007-04-20T15:41:00.000+02:002007-04-20T15:41:00.000+02:00Very good Idea, and fairly obvious. For variables ...Very good Idea, and fairly obvious. <BR/><BR/>For variables I tend to add a local variables I tend to add a v in front (vStartDate) while with variables in a Class I use Delphi's defualt F (FStartDate) Constants always a c (cDefault).<BR/>But in the bad code I am currently working in it usually is a wild guess of what any variable means and two lines later it might've changed. (ns. That's before I touched the code.<BR/>Oh the Joys (sic) of inheriting code at a new work.)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-29331675.post-83270790402682110292007-04-20T13:19:00.000+02:002007-04-20T13:19:00.000+02:00I don't feel a need to distinguish properties from...I don't feel a need to distinguish properties from methods but I do stronly distinguish variables from everything else by always starting a variable in a lowercase letter and everything else in an uppercase letter.gabr42https://www.blogger.com/profile/06903558857617342477noreply@blogger.comtag:blogger.com,1999:blog-29331675.post-67536206989053644042007-04-20T13:04:00.000+02:002007-04-20T13:04:00.000+02:00I like your idea. I’ll consider using it.By the wa...I like your idea. I’ll consider using it.<BR/><BR/>By the way, I’ve also noticed that the way I format my code changes over time. The only thing that remains is my paranoiac desire to add empty braces () to a procedure/function calls/declarations which take no parameters (C++-syntax-like).<BR/>dummy:= foo();<BR/>This is how I distinguish variables/properties from methods.<BR/>Also, I hate with fierce hatred adding semicolon before “end”.<BR/>procedure p();<BR/>begin<BR/> if dummy = 1 then<BR/> begin<BR/> foo1();<BR/> foo2()<BR/> end<BR/>end;Anonymousnoreply@blogger.com