Programming standards...no flaming please!
-
Going through a function and saw this: Print(FileNumber, CStr(System.Math.Round(.Horiz.ZBracedAllowableLoad(Garbage) * Tower.AllowableStressIncrease, 2)) & ",") Guess what garbage is? Dim Garbage As String = "" So I emailed my boss (in TX). Here is the conversation. Me: Why the one space of garbage? Him: The function being called there returns a value in that parameter, but in this case, it is not needed Me: Okay, maybe this is a dumb question, but why not overload that function to not return a value? Him: Not a huge priority, it could be….
leckey wrote:
Not a huge priority, it could be….
Translation: "I can't design software." Hell, I don't even use "sometimes unused" output params in C. Hey, he's not my boss, so I can say it. :laugh: Jeremy Falcon
-
If you inherited it from someone within the company, go and smack them on the head. No code file should be 10k lines. Some functions may tend to be long, but they should be refactored where-ever possible, ideally I would say 30 lines is a max for a function. The book that covers all of this is called Code Complete. If you don't own it, buy it. While I found I knew most of what it was saying, I still found it exciting to see it all in written form, with logical explanations for the benefit of people like the clown who wrote the code you're now looking at. I am however cautious about refactoring existing code, do it if you can, but beware, lest you go crazy and spend heaps of time chasing an ideal that may introduce bugs in code that already works. Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Christian Graus wrote:
The book that covers all of this is called Code Complete
4 cups of coffee: $3.25 Bag of M&M peanuts: $2.49 Surfing Code Project: Free Don Miguel's comment on Code Complete[^]: Priceless There are some things money can't buy, for everything else there's Mastercard :-D
-
led mike wrote:
I once touched VB with a ten foot pole.
What happened to the 10 foot pole? Did it rot apart?
-
led mike wrote:
No he hated VB so he quit and moved back to Poland.
:laugh::laugh::laugh:
-
I wasn't really sure if this belonged to a particular message board so please no flaming! I am wondering what others habits are when it comes to programming. I just inherited a huge VB.NET program. In one VB page it has over 10k lines of code. One function within that has about half those lines. Do you have a "limit" on how big/small a function/method/class should be before breaking it into smaller parts? We just used the analyzer on this thing and found one case statement has over 70 routes to go. So I'm hoping to clean this puppy up. BTW...heat index is currently at 109 degrees. Hope everyone else is staying cool.
leckey wrote:
We just used the analyzer on this thing and found one case statement has over 70 routes to go.
Wow - I missed this. Huge case statements sometimes show a need for polymorphism ( that is, each case becomes a class ). Other time, they just may show incompetence. Does it have 70 different cases, or is it rife with goto statements ? Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
leckey wrote:
We just used the analyzer on this thing and found one case statement has over 70 routes to go.
Wow - I missed this. Huge case statements sometimes show a need for polymorphism ( that is, each case becomes a class ). Other time, they just may show incompetence. Does it have 70 different cases, or is it rife with goto statements ? Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
I'm not sure. He was playing with the new analyzer we got and just told me about it. I'm just starting to go through the code to figure it out. It's an engineering program so it's a lot of "trying" to get the smallest weight depending on the factors (of which there seem to be a zillion).
-
Christian Graus wrote:
The book that covers all of this is called Code Complete
4 cups of coffee: $3.25 Bag of M&M peanuts: $2.49 Surfing Code Project: Free Don Miguel's comment on Code Complete[^]: Priceless There are some things money can't buy, for everything else there's Mastercard :-D
-
While I did have formal training in the form of a CS degree I taught myself coding long before I was degreed. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane
Me too. But I'm not offended, I'd expect more self taught people to write bad code than good. Although, sometimes I think more formally trained people write bad code than good.... Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
I wasn't really sure if this belonged to a particular message board so please no flaming! I am wondering what others habits are when it comes to programming. I just inherited a huge VB.NET program. In one VB page it has over 10k lines of code. One function within that has about half those lines. Do you have a "limit" on how big/small a function/method/class should be before breaking it into smaller parts? We just used the analyzer on this thing and found one case statement has over 70 routes to go. So I'm hoping to clean this puppy up. BTW...heat index is currently at 109 degrees. Hope everyone else is staying cool.
leckey wrote:
We just used the analyzer on this thing and found one case statement has over 70 routes to go.
Ha, I once had to fix one that only had 30 branches, but each branch had it's own 10 branch case statement that were all cut and pasted from one original and had one or two cases modified in each of the 30 branches. As far as advice for fixing it goes. Clean it up in VB first before you try to convert it to any other language. Otherwise you are merging understanding the code and translating it into one step which will cause more problems.
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
-
I'm not sure. He was playing with the new analyzer we got and just told me about it. I'm just starting to go through the code to figure it out. It's an engineering program so it's a lot of "trying" to get the smallest weight depending on the factors (of which there seem to be a zillion).
leckey wrote:
It's an engineering program
ROTFLMAO :laugh::laugh::laugh::laugh::laugh::laugh: :laugh::laugh::laugh::laugh::laugh::laugh: Yes we are writing this engineering program in VB! What's next building a space craft out of bricks? Some days CP is one of the funniest .... ummm whatever.... tired from laughing now.
-
leckey wrote:
It's an engineering program
ROTFLMAO :laugh::laugh::laugh::laugh::laugh::laugh: :laugh::laugh::laugh::laugh::laugh::laugh: Yes we are writing this engineering program in VB! What's next building a space craft out of bricks? Some days CP is one of the funniest .... ummm whatever.... tired from laughing now.
-
I know...I know. It does interact with another 3rd party product that uses FORTRAN. Glad I could make you laugh though....as I cry while going through this code.
leckey wrote:
I know...I know. It does interact with another 3rd party product that uses FORTRAN.
:omg:
-
leckey wrote:
I know...I know. It does interact with another 3rd party product that uses FORTRAN.
:omg:
-
Me too. But I'm not offended, I'd expect more self taught people to write bad code than good. Although, sometimes I think more formally trained people write bad code than good.... Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
There are more people that write bad code than good. Formal training, unf., doesn't even enter into the equation. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane
-
leckey wrote:
Unfortunately, it's my BOSS.
Then tread with care, but still indicate that a lot of refactoring is required in the interest of maintainability.
leckey wrote:
I am hoping to persuade said boss to let me rewrite this evil thing in C#.
I've done conversions of large projects to C# using automated tools, and it went pretty well. I wouldn't advocate a move of language on the basis that this would solve any problems, but if you're more comfortable with C# ( as I am ), then it's a good move to start with. It also has the benefit that perhaps the boss doesn't know C#, so he won't be able to tinker with it again.... Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
10K lines in one function? Heck, *I'll* come smack your boss. And if he gives you the "what is wrong with the code" look/comment, it is a *BAD* sign. :) Btw, I'll second the recommendation on Code Complete. I do not agree with everything he says, but I would categorize the book as an excellent source of how to code. It should be required reading for every programmer. What I cannot agree with is the relatively arbitrary 30 lines/function rule (give or take). Some concepts that code implements don't make sense broken up - the multiple functions don't help the clarity. And clarity is the goal. Charlie Gilley Will program for food... Whoever said children were cheaper by the dozen... lied. My son's PDA is an M249 SAW.
-
led mike wrote:
hehehehe if I don't stop laughing soon I will need to got to hospital
I am glad I've had a few :beer: so far :)
-
10K lines in one function? Heck, *I'll* come smack your boss. And if he gives you the "what is wrong with the code" look/comment, it is a *BAD* sign. :) Btw, I'll second the recommendation on Code Complete. I do not agree with everything he says, but I would categorize the book as an excellent source of how to code. It should be required reading for every programmer. What I cannot agree with is the relatively arbitrary 30 lines/function rule (give or take). Some concepts that code implements don't make sense broken up - the multiple functions don't help the clarity. And clarity is the goal. Charlie Gilley Will program for food... Whoever said children were cheaper by the dozen... lied. My son's PDA is an M249 SAW.
charlieg wrote:
relatively arbitrary 30 lines/function rule
I tend to regard that as a good guide, but I would say people who convolute their code to reach that aim are doing as much harm as people who don't pay attention at all. I find it's a good guide, but I won't even make my code more complex in order to reach it. It's more a good starting point than an immutable law, IMO. Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
charlieg wrote:
relatively arbitrary 30 lines/function rule
I tend to regard that as a good guide, but I would say people who convolute their code to reach that aim are doing as much harm as people who don't pay attention at all. I find it's a good guide, but I won't even make my code more complex in order to reach it. It's more a good starting point than an immutable law, IMO. Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
I wasn't really sure if this belonged to a particular message board so please no flaming! I am wondering what others habits are when it comes to programming. I just inherited a huge VB.NET program. In one VB page it has over 10k lines of code. One function within that has about half those lines. Do you have a "limit" on how big/small a function/method/class should be before breaking it into smaller parts? We just used the analyzer on this thing and found one case statement has over 70 routes to go. So I'm hoping to clean this puppy up. BTW...heat index is currently at 109 degrees. Hope everyone else is staying cool.
Try to keep a function to one page. A guide, not a rule however. Elaine :rose: The tigress is here :-D
-
Christian Graus wrote:
The book that covers all of this is called Code Complete
4 cups of coffee: $3.25 Bag of M&M peanuts: $2.49 Surfing Code Project: Free Don Miguel's comment on Code Complete[^]: Priceless There are some things money can't buy, for everything else there's Mastercard :-D
led mike wrote:
Don Miguel's comment on Code Complete[^]: Priceless
Please explain what is good about that. You've posted this as being some high-quality post-of-the-year a few times, but I fail to see anything that stands out about it.
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"