Anyways, there always seems to be some massive desire to break up large methods into small methods for no other reason that people don't like large methods. These people usually have a hard on for Uncle Bob and his dribbling tulipe pile of a book. If a method is a workflow service type arrangement often it is best leaving it in that state.
- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Code reviews
Collapse
X
Collapse
-
-
Originally posted by tarbera View PostThe poor sod who has had to fire the out of control new programmer 'Who knows best' but knows nothing.
(that's like a backup system in PM terms)Originally posted by MaryPoppinsI'd still not breastfeed a naziOriginally posted by vetranUrine is quite nourishingComment
-
Originally posted by minestrone View PostAnyways, there always seems to be some massive desire to break up large methods into small methods for no other reason that people don't like large methods. These people usually have a hard on for Uncle Bob and his dribbling tulipe pile of a book. If a method is a workflow service type arrangement often it is best leaving it in that state.
This is my experience yours might be different, just wanted to say there are lots of good reasons to refactor monolithic classes/methods.Comment
-
Originally posted by d000hg View PostYeah, if only they'd use source control.
(that's like a backup system in PM terms)Last edited by eek; 6 January 2014, 19:25.merely at clientco for the entertainmentComment
-
Originally posted by woohoo View PostLarge methods are usually harder to follow and maintain. If it's doing multiple things then it's harder to re-use the code, refactor and unit test. Often you end up with a tangled mess of code that's difficult to change without breaking something else. You can also end up with lots of repeated code because programmers cant be arsed refactoring the mess of code and just cut and paste.
This is my experience yours might be different, just wanted to say there are lots of good reasons to refactor monolithic classes/methods.
The first half of this presentation convinced me to almost take this to extremes. Watch around 3 minutes - "methods more than one method long are a code smell" - Aloha Ruby Conf 2012 Refactoring from Good to Great by Ben Orenstein - YouTubeComment
-
Wow. Thanks for the replies.
There's a whole lot of crazy in this thread. It's possible the scope of change we're talking about is being overestimated (refactoring != redesign). I'm really shocked by some of the responses.
Originally posted by Kanye View PostMy view was always that you should leave code better than you found it. If you can make simple refactorings such as pulling methods to improve readability, reuse, testablity then its basically your responsibility as a professional to do that.
Code-rot is a fact of life; and once the rot's set in, if i intertwine new functionality with rotten code I'm just catalysing the whole rotting process.
Comparisons to a decorator doing the wallpaper/ceilings/etc when he was only asked to paint the skirting boards are the wrong analogy. It's more akin to the painter discovering that the skirting boards are peeling badly, so he does a professional job and sands them down first rather than just slapping a new coat on top of the peeling paintwork. The painter isn't interested in the wallpaper or ceilings, and limits the scope of his professionalism to the area which he's been assigned to improve.
Plus the new feature/fix i've implemented is now unit tested, along with whatever i've been able to make testable in the process.
And Tarbera - get a clue! Worst case you see what i've done, say "nice effort, but there are particular risks in this project which you wasn't aware of and it'll be too expensive to redo the performance testing". Then it takes me 3 minutes to revert the code back to it's original state (Oh! not even that because it's not even merged into the release branch because it;s not been approved yet), and you can not pay me for 3 hours of my time, or I can make it up and I'll know better next time.
So a change in a variable name requires same performance testing as breaking a 1000 line program into 15 sub procedures -
Are you one of those excel-monkey (clueless) PMs who has to manufacture importance for themselves?
Anyhow, like i say it's possible some people have overestimated the scale of the refactoring (or just aren't very good at refactoring), so ignore me if that's the case.
Had another batch of reviews today, with a different guy, which went well - infact he started calling me out on the inappropriate multiple responsibilities a particular class was holding, before I pointed out that he was looking at the previous commit, rather than the new one, on the diff. So I might have just got the cantankerous bad egg previously.
I didn't expect a whole load of pages arguing whether it is right or wrong to maintain code as you work with it - it's something I've always taken for granted (at least in my more experienced years after having had a chance to work with the real pros).
I just wanted to see who else was frustrated working with the software dung-beetles who like to live & work in tulip.Last edited by SpontaneousOrder; 6 January 2014, 21:22.Comment
-
Originally posted by minestrone View PostAnyways, there always seems to be some massive desire to break up large methods into small methods for no other reason that people don't like large methods. These people usually have a hard on for Uncle Bob and his dribbling tulipe pile of a book. If a method is a workflow service type arrangement often it is best leaving it in that state.
Where I decide to break the methods up is when there are comments in the code, and the comments are necessary. In my experience it is incredibly rare to actually need to put any comments in the code, and often (As in the example i'm posting about) the comments say that the code does something different to what it actually does.
If the code actually NEEDS comments, and a broken-down collection of methods doesn't then need any comments, then do you think thats a strong indicator to do the refactor?
Or are you fine with comments in code (I know lots of people are) ?
I don't like playing the "do i feel lucky, punk?" game when reading comments - so i'd rather just read the code and understand it than having to read the comments, and then read the code as well just to make sure they match.Comment
-
Originally posted by woohoo View PostLarge methods are usually harder to follow and maintain. If it's doing multiple things then it's harder to re-use the code, refactor and unit test. Often you end up with a tangled mess of code that's difficult to change without breaking something else. You can also end up with lots of repeated code because programmers cant be arsed refactoring the mess of code and just cut and paste.
This is my experience yours might be different, just wanted to say there are lots of good reasons to refactor monolithic classes/methods.
Methods should be sized to do a specific task, dogmatically designing your code based on LOC is wrong, as is designing your class for ease of testing. The cleanest code comes from clarity of the interface and the worst thing you can do for that is create methods based on size and methods that make it easier to get your lines of code tested percentage up.Comment
-
Originally posted by SpontaneousOrder View PostWow. Thanks for the replies.
There's a whole lot of crazy in this thread. It's possible the scope of change we're talking about is being overestimated (refactoring != redesign). I'm really shocked by some of the responses.Comment
-
Originally posted by minestrone View PostMethods should be sized to do a specific task, dogmatically designing your code based on LOC is wrong, as is designing your class for ease of testing. The cleanest code comes from clarity of the interface and the worst thing you can do for that is create methods based on size and methods that make it easier to get your lines of code tested percentage up.
Class level single responsibility, though, tends to make testing easier as a side effect. Single reason to change = helpful, easier to test = bonus!
+1 on the not designing code for testability though (apart from special cases).Comment
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers
Contractor Services
CUK News
- Is it legal to work remotely from Europe via a UK company? Sep 5 22:44
- Is it legal to work remotely from Europe via a UK company? Sep 5 10:44
- Autumn Budget 2025 set for Nov 26, ‘putting contractors on watch’ Sep 4 15:13
- November 2025 Companies House ID rules contractors must follow Sep 3 19:12
- When agencies sink with your contractor invoice: a legal guide Sep 2 17:14
- Reeves ‘to raise VAT registration threshold to £100,000’ Sep 1 06:37
- When your agency shuts: a recruiter’s 5 tips if you’re unpaid Aug 29 06:57
- What the 2025 employment status review means for contractors Aug 28 06:39
- Contractors, Autumn Budget 2025 is set to extend the big income tax freeze Aug 27 07:15
- Labour to run employment status consultation ‘before 2026’ Aug 26 05:03
Comment