I've read up on and try to follow object orientated principals as much as I can when I write code... but now I'll be redoubling my efforts.
Previously the projects I've worked on have been written quite well, however the one I have been working on today has just been terrible! No label names, few other names, comboboxes are have mixed prefixes "cb" and "ddl"... no comments that aren't excluded code.
I really get why this stuff is important now!
*rages*
Should have been a quick job, just replacing Krypton forms with normal WinForms... instead I spend all day, going back and forth between two visual studios so I can see wtf "button1" (etc) is for.
(it's "for the lose".)
Smelly Code
Page 1 of 17 Replies - 594 Views - Last Post: 30 December 2011 - 09:44 AM
Topic Sponsor:
Replies To: Smelly Code
#2
Re: Smelly Code
Posted 22 December 2011 - 10:23 AM
Other than just ranting... Where do you see this going as a discussion?
Yeah - bad coding habits, lack of consistency, lack of comments, all your typical rookie stuff, is well.. bad rookie behavior. We all did it. We all know its bad.
Yeah - bad coding habits, lack of consistency, lack of comments, all your typical rookie stuff, is well.. bad rookie behavior. We all did it. We all know its bad.
#3
Re: Smelly Code
Posted 22 December 2011 - 10:25 AM
The use of Hungarian notation as you're seeing has actually been deprecated and would be picked up by FxCop as something to be fixed. However, I think there actually is a difference between ddl (drop-down list) and cb (combo box), isn't there? The former being non-editable, the latter editable.
Could be wrong though. Been a while.
But yes; as someone who has done tons of maintenance work over the years, readability is very important. I try very hard to use variable, class, and method names that reflect the actual intended use of the item.
Could be wrong though. Been a while.
But yes; as someone who has done tons of maintenance work over the years, readability is very important. I try very hard to use variable, class, and method names that reflect the actual intended use of the item.
#4
Re: Smelly Code
Posted 22 December 2011 - 10:33 AM
hungarian notation may be deprecated in the 'official' world... but not in mine.
Numerous times I go back to a project I haven't opened in months. I don't always recall the names of controls or properties. But I do know it is a combobox or a listview or whatever. By using consistent notation I can start typing cbo and Intellisense will popup a list of all the comboboxes.
then there is the ability to make find/replace easy and meaningful and to have all the things related to the same thing obviously and human readably related. In this example if I need to rename UserValue to UserAge then a find/replace all hits everything related at once: The public property, the private value behind, the combobox, the button
Numerous times I go back to a project I haven't opened in months. I don't always recall the names of controls or properties. But I do know it is a combobox or a listview or whatever. By using consistent notation I can start typing cbo and Intellisense will popup a list of all the comboboxes.
then there is the ability to make find/replace easy and meaningful and to have all the things related to the same thing obviously and human readably related. In this example if I need to rename UserValue to UserAge then a find/replace all hits everything related at once: The public property, the private value behind, the combobox, the button
private int _UserValue;
public int UserValue
{
get { return _UserValue; }
set
{
_UserValue = value;
tbUserValue.Text = value;
}
}
public btnUserValue_Click(object sender, eventargs e)
{
// SOme related button method
}
#5
Re: Smelly Code
Posted 22 December 2011 - 11:27 AM
I can't get with Hungarian, personally - if you're using a typed language, that is. Those of you writing in traditional BASIC or PHP can go ahead with it.
If you're using an IDE, it should be keeping track of objects for you, no need to make your names illegible for that. If you're not using an IDE, grep will find you all of the declarations of a particular type, so that's not a problem.
That's a matter of style, though. If the project is using Hungarian, you go with it. Worse things happen at sea, and all that. What gets me is the inconsistent usage. There's absolutely no point - and I think we can all agree on this - in using Hungarian sometimes. If you're using a naming convention on a project, you have to spell it out before you use it, and everyone has to use it throughout, not just when they remember.
That's a matter of style, though. If the project is using Hungarian, you go with it. Worse things happen at sea, and all that. What gets me is the inconsistent usage. There's absolutely no point - and I think we can all agree on this - in using Hungarian sometimes. If you're using a naming convention on a project, you have to spell it out before you use it, and everyone has to use it throughout, not just when they remember.
#6
Re: Smelly Code
Posted 22 December 2011 - 12:10 PM
My apologise for the ambiguously declared discussion.
I only use Hungarian with Forms, it may not strictly be necessary but I don't really see a downside as I describing its purpose in the rest of the name.
It does group your form components nicely in the properties drop down and IntelliSense, I have used it with Find/Replace as described to.
Jack: I haven't heard that before but in this case they where both the exact same component, it was clear they where performing the same type of task when looking through the project.
I only use Hungarian with Forms, it may not strictly be necessary but I don't really see a downside as I describing its purpose in the rest of the name.
It does group your form components nicely in the properties drop down and IntelliSense, I have used it with Find/Replace as described to.
Jack: I haven't heard that before but in this case they where both the exact same component, it was clear they where performing the same type of task when looking through the project.
#7
Re: Smelly Code
Posted 30 December 2011 - 09:22 AM
Have you considered renaming things and adding comments as you work out what things do? You don't have to overhaul the entire project, just leave things a little tidier than you found them.
#8
Re: Smelly Code
Posted 30 December 2011 - 09:44 AM
Page 1 of 1
|
|

New Topic/Question
Reply

MultiQuote









|