(no subject)
Feb. 22nd, 2005 01:37 pmIf I ever see another piece of code WrittenWithStudlyCaps, IAmGoingToScream.
I think I need to get around to writing an LJ entry about readable coding styles sometime...
I think I need to get around to writing an LJ entry about readable coding styles sometime...
(no subject)
Date: 2005-02-22 06:52 pm (UTC)I don't care much about what coding style is in use, as long as I can tell Emacs how to replicate it.
(no subject)
Date: 2005-02-22 06:56 pm (UTC)Plus, a missed capitalization could make for a bug that's very difficult to spot.
(no subject)
Date: 2005-02-22 07:08 pm (UTC)(no subject)
Date: 2005-02-22 07:12 pm (UTC)Perhaps I should have worded my complaint better.
Let's say I'm working on a piece of code for the first time and there is a variable called FluxCapacitorIsThePower. If it's a weakly typed language that doesn't require me to initialize my variables, and I accidentaly type FluxCapacitorIsthePower in some place, I'm goint to have a hard time finding that. I think I would have a much easier time finding a missing character or underscore than I would have finding one that isn't capitalized properly.
(no subject)
Date: 2005-02-22 07:16 pm (UTC)True, in a language that does not require you to explicitly declare your variables (a different statement than yours; weak typing and initialization requirements have nothing to do with implicit variable declaration), and is also case sensitive, this would be a problem.
Do any such language exist? I can't think of any offhand.
(no subject)
Date: 2005-02-22 07:26 pm (UTC)I can cause such breakage in PHP with the following code:
This results in printing the value "1" on the first line, and nothing on the second line.
(no subject)
Date: 2005-02-22 07:29 pm (UTC)s/Foobar/foobar/g
(no subject)
Date: 2005-02-22 07:33 pm (UTC)Just by glancing at that code, I have a much easier time of figuring out is wrong. Clearly one variable name is longer than the other, and one has what my brain parses as a space in it.
Maybe our brains just work differently. :-)
(no subject)
Date: 2005-02-22 07:51 pm (UTC)s/, an.*/\./
(no subject)
Date: 2005-02-22 06:57 pm (UTC)Then you won't like Cocoa...
Date: 2005-02-22 06:59 pm (UTC)baseDir = [somePathString stringByDeletingLastPathComponent];
But I bet you can tell exactly what that method does, which is much better than the POSIX way where such a function would be called "strdlpc". And it's not difficult to type, as long as you have code completion. :-)
Re: Then you won't like Cocoa...
Date: 2005-02-22 07:08 pm (UTC)Oh man, don't even get me started on that.
Why do people need IDEs for writing code, anyway? What's wrong with vim and a little syntax highlighting?
Re: Then you won't like Cocoa...
Date: 2005-02-22 07:09 pm (UTC)Re: Then you won't like Cocoa...
Date: 2005-02-22 07:15 pm (UTC)Then I can write the function call with the proper parameters and delete the copied function line when I'm done. That approach has served me well in the past.
Re: Then you won't like Cocoa...
Date: 2005-02-22 07:18 pm (UTC)functionname(
and up pops the parameter list.
In JBuilder, if javadoc documentation exists for the fuction, that is also displayed.
Re: Then you won't like Cocoa...
Date: 2005-02-23 07:03 am (UTC)Old, obscure methods, no matter how quickly and efficiently used by a master of such techniques will always lose to the paradigm of easier.
When it comes to fresh blood in the industry only masochists avoid the path of least resistance.
Just my fiftieth of a dollar.
Re: Then you won't like Cocoa...
Date: 2005-02-23 02:55 pm (UTC)Oh, wait.
As I just illustrated, new technologies aren't always better, nor do they necessarily make you more productive. Case in point: vi/emacs. I work with some damned talented people in my office here, and everyone uses vi/emacs, straight from the command line. Nobody here uses any "visual editor", because the bloat of such would outweigh the increased speed in code writing. (As much as I liked BBEdit back when we worked in Allentown, it's quicker for me to ssh into the box, cd to the directory, and start up vi. Really.)
Another important thing to consider is that Shiny Code Writing Tools don't necessarily make up for ineptitude of the person behind the keyboard. Example: How many Visual Basic programmers do you know who are absolutely clueless about the fundamentals of programming? All the tools in the world won't help them architect better code.
(no subject)
Date: 2005-02-22 07:25 pm (UTC)What ticks me off a lot more, tho, is how some people use unfathomably nondescriptive variable names like iTrp or cWtt. And convince themselves they're easy to decipher and good programming practice because the first letter indicate the type. Oh yeah, thanks a lot, that makes it easy for me to find the place they're declared. I still have to go through the whole code to figure out what the heck it's used for.
(no subject)
Date: 2005-02-22 07:31 pm (UTC)If memory serves, it came about because there were M$ programs that literally had dozens of variables in a particular namespace. Rather than doing something sensible such as say, refactoring the code or grouping like variables into arrays/hash tables, they decided instead to change the names of the variables to use Hungarian Notation to indicate what was stored in the variable. Ugh.
-- Giza (and you thought there was some nasty Perl code out there...)
(no subject)
Date: 2005-02-23 02:02 pm (UTC)(no subject)
Date: 2005-02-22 07:55 pm (UTC)Perl's coding standards may not coincide. But there's a lot of perfectly mainstream languages that do, and even outside coding standards at the language level, different shops have different standards. So just get used to the fact that it will be different at every job you hold.
(no subject)
Date: 2005-02-22 08:12 pm (UTC)> was that again? Who knows.)
Viewing that in a fixed width, I can easily count 4. :-)
My own coding standard on leading underscores is that I will start private methods/vars in a class with 1 underscore[1]. The only exception to this is when I code in Python, which mandates two leading underscores for private data. But in that case, I will never start anything in Python with a leading underscore.
[1] I originally did this in PHP 4, since there was no support for private vars/functions in classes. I ended up keeping that notation because I discovered that it helped me keep track of which functions were publicly callable and which were not just by looking at the function name.
(no subject)
Date: 2005-02-22 08:00 pm (UTC)Back when computers were steam powered, we used to use LETTERS for variables and you never knew what they stood for and we liked it just fine!
----------------------------------------------------------
David M Stein
"GOD is REAL.. Unless declared integer."
(no subject)
Date: 2005-02-22 08:03 pm (UTC)commFlag
bytearrayIndex
pidloopError
diallistPtr
mainloopState
I only throw one Cap into any name where appropriate. It's handy, though I can certainly see where long, drawn out names like those would be a pain to read.
(no subject)
Date: 2005-02-22 10:08 pm (UTC)1. an underscore is about 3 times slower for me to type than a capital letter. Capital letter = right finger + left finger.
Underscore = right finger + right finger. Also, I can touchtype common alphanumeric characters, whereas the underscore is one of the least used characters, making its use both slower and more error prone
2. It makes code easier to parse to me. Yes, underscores parse as spaces, and I don't want that. Spaces translate to new functions/variables, it makes it harder to see where the function_with_a_lot_of_words ends and where its parameters kick in.
Personal preference.
(no subject)
Date: 2005-02-22 10:09 pm (UTC)(no subject)
Date: 2005-02-22 10:18 pm (UTC)Does this slow you down? I mean, for me, doing an underscore is right pinky finger + right middle finger. It's become second nature to me.
> Spaces translate to new functions/variables, it makes it harder to see where
> the function_with_a_lot_of_words ends and where its parameters kick in.
Isn't that what the opening parenthesis is for? o.O
(no subject)
Date: 2005-02-22 11:38 pm (UTC)void exampleFunctionNumberOne(int hello, float goodbye)
void example_function_number_one(int hello, float goodbye)
The first one, for me, is far clearer when it comes to seeing where the variables start. I could've cheated and put a space before that first int and made it even more obvious, but I don't really do that in practice. The division the space provides between "function name" (and unimportant designator) and "input variables" is worth the hassle of midname caps.
(no subject)
Date: 2005-02-22 11:53 pm (UTC)In that list, the last one is what I would write, and what I would find to be most readable. Then again, in a proper context, it would really look more like:
void example_function_number_one (int hello, float goodbye) {...which I think makes it look even more readable, thanks to the trailing brace that starts the code block of the function.
The more discussion I see on this entry, the more I'm beginning to think that different peoples' minds work different on matters such as this.
(no subject)
Date: 2005-02-23 11:07 pm (UTC)(no subject)
Date: 2005-02-24 04:27 am (UTC)> is right pinky finger + right middle finger. It's become
> second nature to me.
I use left + right for the underscore. Am I weird?
Here is another aspect...
Date: 2005-02-23 11:15 am (UTC)char *my_string = "hello world";NSString *myString = [NSString stringWithUTF8String:my_string];
"my_string" is a traditional null-terminated C string, while "myString" is a Cocoa NSString object. If often mix these two styles when I call C functions from Cocoa. I associate underscores with low-level (C) functions, and studly caps with the higher-level (Cocoa) functions, classes or methods.
Re: Here is another aspect...
Date: 2005-02-23 11:08 pm (UTC)(no subject)
Date: 2005-02-23 03:11 pm (UTC)Yes, it does work.
(no subject)
Date: 2005-02-23 11:08 pm (UTC)(no subject)
Date: 2005-02-23 07:16 pm (UTC)[DEATH TO ANYONE WHOSE RECORD-LENGTH EXCEEDS 72 COLUMNS]
(no subject)
Date: 2005-02-23 11:08 pm (UTC)http://c2.com/cgi/wiki/
(no subject)
Date: 2005-02-23 11:34 pm (UTC)