Programming standards...no flaming please!
-
leckey wrote:
one VB page it has over 10k lines of code
:omg:
leckey wrote:
one case statement has over 70 routes to go
:wtf: This is a definitive candidate for a refactoring tool. I would say even one class with over 1000 lines is too big. That's normally the point when I begin to rethink what I'm doing...
Robert Rohde wrote:
That's normally the point when I begin to rethink what I'm doing...
That's the point where the developer needs to begin to think, nevermind rethink! :) :josh: My WPF Blog[^]
-
Our heat index is the same here! If a function can be broken up, break it up. With care. If some functionality can be reused then it will likely be reused and breaking it into more distinct methods and classes really help. Remove use of globals? Were possible. While members are extrememly useful and necessary I often see them used as globals to avoid parameter passing when in fact parameter passing is the best way to go. If you are passing more than 5 parameters you probably have too many parameters If you look at your finished product and it does not appear neat and elegant it probably isn't Switch to c# Use your best judgement with any thing you do. And remember the first several times you do something it is wrong. Fearless refactor is something to live by. Oh, yeah, almost forgot, add unit tests. See: NUNIT and use xml comments and extensive source comments. (Ok more advice) In business applications readability and maintainability and self-documentation is more important that the absolute fastest code [in most cases]. 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
Ennis Ray Lynch, Jr. wrote:
Switch to c#
*grin* That may be an effective filter to increase the odds of people who write 5000 line functions never working on the code again, but beyond that I don't see how moving to C# is a good thing. I've done large VB -> C# moves, and there's always a lot of stuff the converters can't fix, or places where the code they write really sucks. One can remove the VisualBasic namespace without moving to C#, if you want to get rid of legacy garbage.
Ennis Ray Lynch, Jr. wrote:
add unit tests.
Adding unit tests to an existing project of any size is a pretty decent sort of task. Unit tests are best written during development, not after. Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
leckey wrote:
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.
Wow, yeah, that needs work. VB.NET standards state that at least 90% of each module must consist of a single method - the original author must not have been a Native VB coder.
---- Scripts i’ve known... CPhog 1.0.0.0 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.2 - printer-friendly forums Expand all 1.0 - Expand all messages In-place Delete 1.0 - AJAX-style post delete Syntax 0.1 - Syntax highlighting for code blocks in the forums
-
Ennis Ray Lynch, Jr. wrote:
Switch to c#
*grin* That may be an effective filter to increase the odds of people who write 5000 line functions never working on the code again, but beyond that I don't see how moving to C# is a good thing. I've done large VB -> C# moves, and there's always a lot of stuff the converters can't fix, or places where the code they write really sucks. One can remove the VisualBasic namespace without moving to C#, if you want to get rid of legacy garbage.
Ennis Ray Lynch, Jr. wrote:
add unit tests.
Adding unit tests to an existing project of any size is a pretty decent sort of task. Unit tests are best written during development, not after. Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
How to fix the code base. BTW, when I convert code bases I retype it. I don't trust automated tools. Besides doing it yourself will give an intimate understanding with the code. Fortunately with .NET you can mix languages and having c# classes definately help you to differentiate new code from old (which is being replaced.) 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
-
The problem is he doesn't have formal training. He just learned as he went along. Hence the bad code ontop of bad code. I'll look at something and ask him why he did that and he'll say it was the only way he knew how to make it work at the time.
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
-
How to fix the code base. BTW, when I convert code bases I retype it. I don't trust automated tools. Besides doing it yourself will give an intimate understanding with the code. Fortunately with .NET you can mix languages and having c# classes definately help you to differentiate new code from old (which is being replaced.) 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
-
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
-
Right now it's a windows application. I'd like to make ASP.NET which again makes me want to start from scratch.
Between a Windows Application and an ASP.NET application other than the GUI code. Keep that in mind when you rewrite. The code and the classes should all be seperate from the GUI code and classes. 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
-
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:
No code file should be 10k lines.
I agree. A code file in my opinion should be 500-1000 maximum.
Christian Graus wrote:
I would say 30 lines is a max for a function.
Same here. If you open it in the good old MS-DOS Edit and it exceeds the number of lines visible on the screen at one time, then it's too big for a function and should be refactored.
-
I certainly didn't mean to insult you or anyone else who learned this way. :sigh: His methods at the time just weren't the best. He also doesn't care about the SDLC like requirements gathering. Just do it/fix it, even if it's ugly.
I was just offering a reminder that formal training is no gaurantee of good results. 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
-
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.
I try and keep my functions to a 10 line max. Unless there's a bit of exception handling and/or database manip, as populating a row with ten fields already busts this, but generally, I try to think atomically. But we have files up to around 3k. A few of em'. I tend to think differently in this regard. If the file is a database helper class with a manager and the like, I like to keep em' all together so I'm not ctrl-tabbing like crazy. But eh.. it depends on your environment. As far as how big it should be before breaking it up.. first if anything repeats, that's a signal to move it out into a function, second, if you could name a section in that it can be defined using English or your language of choice, I'd move it out. Again, I just try to think atomically. [edit] And I'd at the least make each case statement a call to a function that handled that case. [/edit] 70 routes... that's alot. If its going to continue to grow, you might be better off dumping a bunch of delegates into hashtable and looking up the case. Keeps the code simpler if your not that worried about max performance. Sounds fun! Except for the VB part. ;) This statement is false. -- modified at 16:47 Wednesday 19th July, 2006
-
Christian Graus wrote:
If you inherited it from someone within the company, go and smack them on the head.
Unfortunately, it's my BOSS. I will look at the book. I am hoping to persuade said boss to let me rewrite this evil thing in C#.
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
-
Right now it's a windows application. I'd like to make ASP.NET which again makes me want to start from scratch.
If your app was written properly, then all you should need to do is write presentation code. I seem to recall answering a question from you tho that showed a ton of business logic in the presentation code, so I am presuming it's probable you don't have a dll of business logic that is called from your presentation executable ? If that's the case, I would certainly aim to change this for the ASP.NET version, write dlls that represent a business logic layer and a data layer, and call those from your ASP.NET pages. Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Christian Graus wrote:
If you inherited it from someone within the company, go and smack them on the head.
Unfortunately, it's my BOSS. I will look at the book. I am hoping to persuade said boss to let me rewrite this evil thing in C#.
leckey wrote:
Unfortunately, it's my BOSS.
:~
leckey wrote:
I will look at the book.
Do so, it is a very good book :)
leckey wrote:
I am hoping to persuade said boss to let me rewrite this evil thing in C#.
Try and persuade your boss from a business approach. Sell him on refactoring to "fine-tune" the code. Not sure what the application does, but fixing it up in C# may have benefits that helps everyone win.
-
How to fix the code base. BTW, when I convert code bases I retype it. I don't trust automated tools. Besides doing it yourself will give an intimate understanding with the code. Fortunately with .NET you can mix languages and having c# classes definately help you to differentiate new code from old (which is being replaced.) 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
Ennis Ray Lynch, Jr. wrote:
BTW, when I convert code bases I retype it.
OK - the code bases I have changed, it's been because I took a job and found the code was VB, and indicated I only did C#. There was really no option for me to hand type them. One I've been on for two years now, and I admit I still from time to time find code that I change to better reflect what C# can do. But after a day, I had a C# code base that worked fine.
Ennis Ray Lynch, Jr. wrote:
Fortunately with .NET you can mix languages
I thought you could only do that in ASP.NET, unless you mean mix languages between different dlls in the project, not within one project ? Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Christian Graus wrote:
If you inherited it from someone within the company, go and smack them on the head.
Unfortunately, it's my BOSS. I will look at the book. I am hoping to persuade said boss to let me rewrite this evil thing in C#.
-
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.
109 - that's about 45 celcius, I think. I'm just home from the US, and Texas/LA were both pretty warm, getting back to winter is hitting me hard. Canada is amazing, it's the height of summer and it pours with rain. I'm told that it stops in September... Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
109 - that's about 45 celcius, I think. I'm just home from the US, and Texas/LA were both pretty warm, getting back to winter is hitting me hard. Canada is amazing, it's the height of summer and it pours with rain. I'm told that it stops in September... 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:
Do you have a "limit" on how big/small a function/method/class should be before breaking it into smaller parts?
No. Object Oriented Analysis and Design is the solution.
leckey wrote:
In one VB page it has over 10k lines of code. One function within that has about half those lines.
I once touched VB with a ten foot pole. :-D I have seen C/C++ code that is just as bad... actually worse since it was using pointers out the arse! Old non structured C code was typically littered with gigantic global structures filled with pointers and giant functions to go with them. allocs and frees all over the place resulting in massive memory leaks. I once saw an entire company port C code to C++ by replacing all the alloc/free calls with new/delete. That was it... done porting to C++! :laugh: "Too many freaks... not enough circuses" :((
-
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:
Do you have a "limit" on how big/small a function
No, so long as it is a clear and understandable. If a section is reused then it should be broken out is more of a rule then just length of code.
leckey wrote:
one case statement has over 70 routes to go.
Just my opinion but that does not sound understandable.
leckey wrote:
I'm hoping to clean this puppy up.
go to it. "Yes I know the voices are not real. But they have some pretty good ideas."