|
Super Lloyd wrote: is it ok to have method that only have one variable, call it x? or mySingleVariable? or myVariableType? or mvType?
Of course x . It will (clearly) show that it is just a local thingy that is not important in the grand scheme of things.
andDontUseCamelCaseIfPossible
Mircea
|
|
|
|
|
Loving it!
|
|
|
|
|
good name length depends on scope size.
it doesn't make any sense to have a 10-char name for a variable that lives for three lines only.
always use a descriptive name that holds the most relevant information, preferably a noun (or adjective)
exceptions: single letter is OK for small loop index, or coordinates (x,y) or EventArgs or when implementing some mathematical/physical formula with strict naming conventions
avoid names that can't be pronounced
avoid names that sound alike
avoid names that are the same except for their casing (exception: property and its backing variable)
avoid confusion, don't have two names that differ only in one char when that would be i/l/1 or o/0
use camelCase for compound names, avoid underscores.
conclusion: abcd is not OK, and abcdefGhijkLmno is worse; and mySingleVariable is not OK.
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.
|
|
|
|
|
out of curiosity I checked some random sample of your code....
(LP#TrayIconBuster)
ToolBarButton64 tbb64=new ToolBarButton64();
ToolBarButton32 tbb32=new ToolBarButton32();
TrayData td=new TrayData();
I think there is a misunderstanding here, you name your variables just as I do!
|
|
|
|
|
true.
however that's not how I would do it today.
I keep learning and improving my practices.
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.
|
|
|
|
|
Luc Pattyn wrote: avoid names that can't be pronounced That's a very subjective thing. I know a few words, including my last name, that none of my teachers in America ever came close to say without ending up with a knot in their tongues.
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
|
|
|
|
|
I'll reformulate: always use names that can be pronounced easily.
And yes, all statements that hold adjectives are subjective, including this one. Humans have learnt to deal with that, machines are still struggling.
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.
|
|
|
|
|
I go for as short as possible without doing myself or anyone else a disservice in terms of retaining the intent of a variable or function name. As early as yesterday I have to break down and get wordy with a function name because there seemed no other way. It kinda felt dirty but it is what it is. RestoreFocusAndSelect()
O and I never abbreviate. I've looked at old code of mine and saw oh, ctrlbindrv and thought how coy.
|
|
|
|
|
Managers aren't allowed to look at my code. The team lead and other devs can of course, but if you try to micromanage me, you may as well expect my resignation EOB.
To err is human. Fortune favors the monsters.
|
|
|
|
|
Yeah! Way to go!
|
|
|
|
|
I learned early on in this business that it pays to be hard nosed about certain things, both for my own sanity, and the good of who I work for.
I also learned to get out early when things looked like they would set me up for failure.
When I interview for a position, I'm the one do the interviewing, because I'm very selective about what kind of shop I'll work for.
I learned that not only can I afford to do this, I can't afford not to, because honestly? There are more bad dev shops out there than good ones, and I have a reputation and my own personal standards to live up to. I will not work for a shop that drags me down due to bad practices and/or bad management.
To err is human. Fortune favors the monsters.
|
|
|
|
|
I am used to far more abstract ways to access data, like directly using hexadecimal memory addresses. That makes me very unobsessed with naming in general. And there are far too many masters of the obvious who name things after, well, obvious or easy to find out things instead of using the variable name to hint at the intention behind a variable.
Anyway, I usually prefer the shorter version. Calling a variable 'ConnectionString' is more than enough. 'ZeroTerminatedArrayOfCharactersWithConnectionInformationForTheApplicationButNotForTheSeparateDatabaseWithUserInformation' might be a little too unwieldy, especially when everything is named like this. And I have seen people go overboard like that. Even with two monitors you can't even read a short line without scrolling.
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
|
|
|
|
|
Variable/Method names should be
descriptive enough to know what it should be
Distinguishable enough from other variables
clear and easy to use
So I'd prefer short names, but if a long name is more appropriate, just do it.
also:
They always taught me : if it's not broken, don't fix it.
Making changes for the sake of changes is never a good idea and I can't imagine a style guideline: "your names should be at least 15 characters long"
|
|
|
|
|
With exception of loops (and other places like x,y,z where there are conventions) I use descriptive names. I find it easier to maintain long term. "But who cares, the code is done" sounds very strange to me - but then I only work on products that goes on for many years (decades) so it's our own foot we are shooting. I have indeed seen a (understandable) change in attitude from people working on single projects where it is just about what is delivered now, not what you can maintain next year.
If a variable ends up with a long name, it means it is hard to explain what it is doing... which is exactly the case where you need the long name.
|
|
|
|
|
|
kmoorevs wrote: As an aside, do you name your UI controls intelligently, or is Textbox1, Textbox2 good enough?
Doing WPF UI this question is not very relevant..
If I were to give a name to UI Element, as it occasionally happen, it usually a short descriptive one
|
|
|
|
|
|
The Lounge[^]
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Another ship sank? Or did they try to raise the last one and then it sank again?
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
|
|
|
|
|
I can't quite bring myself to feel terribly sorry for anyone who can afford any of these cars.
Especially when, y'know, you don't pay in advance when buying a new car.
|
|
|
|
|
Years ago I spent quite some time in the little town of Ashby de la Zouch in central England doing a technology transfer from the Transmitton company. I also spent a day or two in London, where I was introduced to "a pint of bitter". I was so impressed with the beer that I made a special trip to the Bass brewery. In Ashby I lived on fish and chips English style, where the chips are nothing at all like American crisps or chips. English chips are fried at a lower temperature, so they remain soft and not crispy. When you buy the dish for take-out, it is typically handed to you in a large white paper cone, seasoned with salt and vinegar, never ketchup, with fried white fish like cod. Yum!
Lately I have developed a craving for this style fish and chips - and I find myself wishing I had a good reason to visit the UK so I can once again taste a few pints of bitter and proper fish and chips. Rats! Now my mouth is drooling!
Get me coffee and no one gets hurt!
modified 1-Mar-22 16:06pm.
|
|
|
|
|
I'm not a fan of "chip shop" chips - "soggy bags of pus" to me - I prefer triple-cooked chips, which are glass-like on the outside and fluffy on the inside. Lot of work for a side dish though!
But "Proper fish" - beer battered Cod, crispy and fresh - that's a good one! Making me hungry now as well ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I spent ten days in Leeds a few years ago at a customer site. My favorite foods were fish and chips, and the maple cake dessert at the pub across the street from my hotel.
Software Zen: delete this;
|
|
|
|
|
A couple decades ago I spent a couple weeks in Redcar at the old British Steel works. Redcar billed itself as the fish and chips capitol of the UK.
Not sure it was true but they were damn good!
|
|
|
|
|
Hi, before the turn of the century you got the stuff wrapped in newspapers, I still remember the stains from the newspaper print on my finger tips.
|
|
|
|