A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.
Ever have one of those moments when you just can't think what to call your variable. You know that you need it but you just can't come up with a name ? It's times like that when you realize that you don't actually know what the variable is going to be used for ! If you did then naming it would be easy ! It's times like that when you need to sit back and look at the bigger picture and perhaps have a cup of tea.
Metasyntactic variables. Probably not the greatest for readability/maintainability :)
...But What Do I Know
Thursday, August 25, 2005
> If you don't know what you're going to use the variable for, how do you know you're going to need it?
That's why he's sitting back and having a cuppa - so he has time to work out what he's actually doing. ;)
He already said that if you can't name it then you should realise that you don't know why you're doing it.
Thursday, August 25, 2005
If you are creating the variable, you have some idea of its purpose, so you'll at least have some related terms in mind. Maybe, you are even trying to pick between a few different words. (I find myself in that situation frequently.)
I go to a coworker and explain what the pros and cons of the words I have in mind are to someone else. Sometimes they'll have a completely different suggestion that's better. Usually, they'll at least have a preference for one or the other.
If not, then pick one among the top few and establish a convention.
I often find myself in a situation where the variable name I want to use would be unwieldy but accurate. Then I end up trying to find a word that means what the string of words it replaces means. I am not sure this is good. This happens to me more often with complex algorithms, or in sections of code that don't seem to have a break. Usually I take it as an indicator that I should be refactoing or reorganizing the section. At my day job we have the "tendency" to put the type (or some indication of the type) at the beginning of the variable name. An example:
would mean an sql parameter that is the equipment type id. This starts to become unwieldy when you take it out of a grid:
I guess I am just lazy and don't want to type.
Has anyone ever had a situation where they know what the variable is going to do, but an english name isn't really practical? I find this happens to me when I have a set of data (amongst many other sets in the same method) that is very specific with what it holds. I can't rightly name a set:
I could say:
but even that seems long, and it doesn't necessarily convey what the true contents of the variable are. Thank god for intellisense.
Wednesday, September 07, 2005
This topic is archived. No further replies will be accepted.Other recent topics
Powered by FogBugz