Ah... I see someone is looking to start a war! ;D
Pascal for this, camel for that, CAPS for another, and _these get underscores, while strThose get a pretty prefix, and so do btnThese. :D
...
I stick mostly to C#, Java, C and VB naming conventions. I like a bit of this and a bit of that. e.g. I like private field names with an _underscore and camel case:
_somePrivateFieldName
I'm not fond of:
m_something-Renegade (December 30, 2012, 11:41 AM)
I'm not much of a coder. But I do work a lot with administrative scripting as part of my job.
In my case, I currently dislike underscores - and very much like CamelCaps - although there was a time when I preferred the exact opposite. (Aging eyesight has a lot to do with it.)-40hz (December 30, 2012, 01:30 PM)
My only suggestion is that whatever coding conventions you adopt, you use them consistently.
My coding style is an ecclectic mixture of thing I picked up along the way. This is a side effect of being self taught, as thre was no one to force me to do things their "correct" way. However one thing that has proven handy is that in addition to commenting I always put a header comment above each function stating (in short) what it is/does.-Stoic Joker (December 30, 2012, 09:40 PM)
Other than I hate the rule we have at work with no underscores! so private variables are thisIsAProperty and public ones are ThisIsAProperty. I know they did it because we should be using autoimplemented properties now... but in some cases you can't and that rule sucks!-wraith808 (December 30, 2012, 12:22 PM)
I sorta get the use of dividers, but what am I missing about Underscores vs Dashes? I somehow mind dashes less, and I have no idea why.-TaoPhoenix (December 30, 2012, 09:54 PM)
In Visual Studio with C# you can add comment documentation above a method very easily by using 3 slashes:
///-Renegade (December 30, 2012, 09:48 PM)
In Visual Studio with C# you can add comment documentation above a method very easily by using 3 slashes:
///-Renegade (December 30, 2012, 09:48 PM)
That depends on which version of VS you're using. For some reason three slashes will break your code in VS2005 (yes I still use it frequently). But I (am nutz and still) primarily work in pure Win32 API C++-Stoic Joker (December 30, 2012, 09:57 PM)
What language are you using? Dashes aren't legal in a lot of languages (I can't think of one where they are legal) because that creates ambiguity, e.g.:Code: C# [Select]
int something = an-integer - another-integer;
Compared with:Code: C# [Select]
int something = an_integer - another_integer;-Renegade (December 30, 2012, 09:57 PM)
(Ghetto) None, becuz I' no programmer bro. I just be a dumb humanities birdie. (/Ghetto)
So my only use case is naming files when I don't feel like seeing a lot of %20's in my file names on remote sites. I use spaces the rest of the time in Windows. So I never ever had a use case for Under_Scores, and now that I'm cranky and senile at an early age they annoy me. : )-TaoPhoenix (December 30, 2012, 10:01 PM)
Ah. Got it. I was thinking way back to when spacing was significant and a single space could break things.-Renegade (December 30, 2012, 10:05 PM)
In Visual Studio with C# you can add comment documentation above a method very easily by using 3 slashes:
///-Renegade (December 30, 2012, 09:48 PM)
That depends on which version of VS you're using. For some reason three slashes will break your code in VS2005 (yes I still use it frequently). But I (am nutz and still) primarily work in pure Win32 API C++-Stoic Joker (December 30, 2012, 09:57 PM)
In Visual Studio with C# you can add comment documentation above a method very easily by using 3 slashes:
///-Renegade (December 30, 2012, 09:48 PM)
That depends on which version of VS you're using. For some reason three slashes will break your code in VS2005 (yes I still use it frequently). But I (am nutz and still) primarily work in pure Win32 API C++-Stoic Joker (December 30, 2012, 09:57 PM)
Maybe it's the Win32 API C++? Because the /// convention works for me in VS2005, and I've been using them religiously. I didn't pay attention to the C++ code- it's mostly get in and get out without making a mess.-wraith808 (December 30, 2012, 10:30 PM)
I had one ... project that I was doing for the office but it hit the wall early last spring due to "Scope Conflicts" (e.g. Nobody could/would nail down exactly WTF'ing thing was supposed to do).-Stoic Joker (December 30, 2012, 10:42 PM)
I've had people define scope as "good". I mean that quite literally. Huh? Yep. Not a joke.-Renegade (December 30, 2012, 11:43 PM)
When pushed, I'l use dashes. When did the battle over Dashes vs Underscores happen? Does someone have a nice meaty 3000 word blog to link to?-TaoPhoenix (December 30, 2012, 01:41 PM)
FWIW - inmostnetwork situations I avoid using both those characters.-40hz (December 31, 2012, 11:04 AM)
What language are you using? Dashes aren't legal in a lot of languages (I can't think of one where they are legal)The (good?) old language Cobolw has them. The dialect I've been using (MF) doesn't even accept underscores as a valid character in variable-names, AFAIK :o-Renegade (December 30, 2012, 09:57 PM)
What language are you using? Dashes aren't legal in a lot of languages (I can't think of one where they are legal)The (good?) old language Cobolw has them. The dialect I've been using (MF) doesn't even accept underscores as a valid character in variable-names, AFAIK :o-Renegade (December 30, 2012, 09:57 PM)-Ath (January 01, 2013, 06:31 AM)
May beOh, perhaps. If they don't pull it again (Java7 was one big friggin' letdown). And even if/when it's included in the language, there's the issue of enterprise adoption. Java usually means enterprise, and enterprise tends to mean tardy. I'm glad we're at least on Java6, there's several projects out there still running Java5 or worse.some daythis year?-ewemoa (January 02, 2013, 08:33 PM)
If you end up with method names that are long or weird, that's often a good indication of a code smell.-f0dder (January 02, 2013, 03:44 PM)
I prefer well-named and small (private) functions/methods over comments. Comments are fine for documenting your public APIs, as well as some implementation details, quirks and hacky workarounds - but other than that, I prefer to split into small and well-defined steps, and let the code speak for itself.-f0dder (January 02, 2013, 03:44 PM)
Use of the ternary operator doesn't mean I'm in the "as few lines of code as possible" camp, though. I often break condition of if-statements into (properly named) booleans or method calls, which obviously results in more code lines... but also in better readability.-f0dder (January 02, 2013, 03:44 PM)
I must admit, I am a big fan of comments :-[. I believe commenting the "intent" of your code is usually worth it. There is not a lot of code outside of textbooks that is really self-documenting, and what seems obvious to you while you are writing the code may take a little time for the next coder (or yourself in a month or two) to figure out.Sure thing - it's a delicate balance, and what seems "self-commenting" to one person is an unreadable mess to somebody else. I've rarely revisited code that I thought was "self-commenting" while writing it which I then couldn't grok later on... but I've often been confused by code which I neither commented nor thought through properly.-Jibz (January 03, 2013, 07:47 AM)
As an example, if you take this simple functionWell... your sut_open is actually an example of what I consider to be "noise" comments - IMHO they don't really tell anything that the individual API calls don't already (I'm not familiar with those APIs, though I guess they're related to performance counters). Personally I'd probably rename make_counterpath() -> make_uptime_counter_path(), and get rid of all the comments...-Jibz (January 03, 2013, 07:47 AM)
Btw, I don't know if it's GeSHI or Chrome, but it looks like most of the identifiers are raised a little above the line (or the operators and keywords lowered) in the code blocks, which is slightly annoying to read:Works fine in the fox of fire, but definitely looks funky in Chrome.
(see attachment in previous post (https://www.donationcoder.com/forum/index.php?topic=33484.msg312740#msg312740))-Jibz (January 03, 2013, 07:47 AM)
Girl fights government for right to use name given by her mother; only ‘approved’ names allowed
REYKJAVIK, ICELAND—Call her the girl with no name.
A 15-year-old is suing the Icelandic state for the right to legally use the name given to her by her mother. The problem? Blaer, which means “light breeze” in Icelandic, is not on a list approved by the government.
Like a handful of other countries, including Germany and Denmark, Iceland has official rules about what a baby can be named. In a country comfortable with a firm state role, most people don’t question the Personal Names Register, a list of 1,712 male names and 1,853 female names that fit Icelandic grammar and pronunciation rules and that officials maintain will protect children from embarrassment. Parents can take from the list or apply to a special committee that has the power to say yea or nay.
In Blaer’s case, her mother said she learned the name wasn’t on the register only after the priest who baptized the child later informed her he had mistakenly allowed it.
“I had no idea that the name wasn’t on the list, the famous list of names that you can choose from,” said Bjork Eidsdottir, adding she knew a Blaer whose name was accepted in 1973.
This time, the panel turned it down on the grounds that the word Blaer takes a masculine article, despite the fact that it was used for a female character in a novel by Iceland’s revered Nobel Prize-winning author Halldor Laxness.
Given names are even more significant in tiny Iceland that in many other countries: Everyone is listed in the phone book by their first names. Surnames are based on a parent’s given name. Even the president, Olafur Ragnar Grimsson, is addressed simply as Olafur.
Blaer is identified as “Stulka” — or “girl” — on all her official documents, which has led to years of frustration as she has had to explain the whole story at the bank, renewing her passport and dealing with the country’s bureaucracy.
Her mother is hoping that will change with her suit, the first time someone has challenged a names committee decision in court.
I had no idea that Iceland, Denmark and Germany were strict about what you can name your kid. Just seems bizarre to me.The urban legend (which I have done no research of whatsoever) goes that the naming laws were introduced after a girl who was conceived during a bombing in WWII was named "Raketta Bombardina". I personally do find that name laws are sane, considering how mean children are to eachother, and given that some parents are clusterfsck insane - as an adult, you can change your name anyway, and the rules there are somewhat more lax.-Renegade (January 03, 2013, 11:56 AM)
As an example, if you take this simple functionWell... your sut_open is actually an example of what I consider to be "noise" comments - IMHO they don't really tell anything that the individual API calls don't already (I'm not familiar with those APIs, though I guess they're related to performance counters). Personally I'd probably rename make_counterpath() -> make_uptime_counter_path(), and get rid of all the comments...-Jibz (January 03, 2013, 07:47 AM)
But I might add a comment on how to actually get at the counter value, since that's not evident from the code if you're not familiar with the Pdh API (hm, you add a counter to the query, but there's no "execute" thingy, and you close the query handle right after the add? That looks quirky, but none of the comments say anything about it.) Oh, and I'd replace sizeof(array)/sizeof(elem) with a lengthof macro (for C++, I'd probably use a template function for it, since it's slightly ever more typesafe, but this seems to be über-pure C code, from the single-line block comments :P).-f0dder (January 03, 2013, 11:43 AM)
I am sorry, I thought it was obvious that this was a single function taken from a file -- there are functions to access the values and close the query as well :Thmbsup:.I guessed that much :) - it's just that, coming back to the code after several months & given the other comments in the function, I'd be wondering "why isn't *this* part being commented?". See next comment, though :P-Jibz (January 03, 2013, 01:11 PM)
And (if you'll excuse the tongue-in-cheek) if you think it closes the query right after adding, then I'll take that as an example that even simple code is not easy to read compared to comments :-[.Ah yes (double-tongue-in-cheek), I obviously got distracted by the comments and didn't read the code properly ;-p-Jibz (January 03, 2013, 01:11 PM)