Linked Questions

180 votes
13 answers
81k views

Lately I've been trying to split long methods into several short ones. For example: I have a process_url() function which splits URLs into components and then assigns them to some objects via their ...
Stas Bichenko's user avatar
21 votes
11 answers
4k views

I've seen an increasing trend in the programming world saying that it is good practice to separate code blocks into their own functions. Obviously, if that code block is reusable, you should do that. ...
dallin's user avatar
  • 412
2 votes
4 answers
343 views

Most of my programming experience is in OOP where I have fully embraced the concepts thereof including encapsulation. Now I'm back to structured programming where I have a tendency to logicaly ...
Chad Harrison's user avatar
133 votes
19 answers
17k views

Whenever I find myself writing the same logic more than once, I usually stick it in a function so there is only one place in my application I have to maintain that logic. A side effect is that I ...
147 votes
6 answers
17k views

Generally I use private methods to encapsulate functionality that is reused in multiple places in the class. But sometimes I have a large public method that could be broken up into smaller steps, each ...
Jordak's user avatar
  • 931
35 votes
6 answers
10k views

I have a large method which does 3 tasks, each of them can be extracted into a separate function. If I'll make an additional functions for each of that tasks, will it make my code better or worse and ...
dhblah's user avatar
  • 1,381
8 votes
12 answers
7k views

I'm new at writing professional code (the bulk of my experience is with personal projects) so excuse me if this is trivial. When I write code I find myself being a little inconsistent with how much ...
CS2020's user avatar
  • 213
4 votes
7 answers
2k views

Another programmer just started working in our team and submitted a patch. What required was to have something that compares and check a couple of conditions and set a property based on the outcome. ...
imel96's user avatar
  • 3,608
10 votes
3 answers
3k views

I am looking for some ideas here. I read the article How should code reviews be Carried Out and Code Reviews, what are the advantages? which were very informative but I still need more clarity on the ...
Karthik Sreenivasan's user avatar
5 votes
3 answers
2k views

I have a philosophical disagreement with one of my co-workers, and I'm trying to get back to basics here. What is the purpose of a method? In this question, consider this example. I was criticized ...
SharkCop's user avatar
  • 239
3 votes
2 answers
1k views

I've heard some developers say that if a variable is only referenced one place, to just replace the reference to it with the value assigned to it. I've also heard developers say if a function is only ...
jinglesthula's user avatar
5 votes
3 answers
531 views

Is it OK to have functions that have single statements? I usually make functions that have single statements. I believe these increases code readability and i am able to write code faster as they ...
Gaurav Grover's user avatar
1 vote
3 answers
302 views

Since what matters is not how the code does it but what it does, would you consider wrapping a function with a different name just to clarify it's behavior in certain situations a good practice? ...
Asics's user avatar
  • 239