All Questions
6,322
questions
354
votes
19
answers
63k
views
How would you know if you've written readable and easily maintainable code? [closed]
How would one know if the code one has created is easily readable, understandable, and maintainable? Of course from the author's point of view, the code is readable and maintainable, because the ...
466
votes
19
answers
196k
views
I've inherited 200K lines of spaghetti code -- what now?
I hope this isn't too general of a question; I could really use some seasoned advice.
I am newly employed as the sole "SW Engineer" in a fairly small shop of scientists who have spent the last 10-20 ...
199
votes
32
answers
45k
views
Is micro-optimisation important when coding?
I recently asked a question on Stack Overflow to find out why isset() was faster than strlen() in PHP. This raised questions around the importance of readable code and whether performance improvements ...
50
votes
2
answers
24k
views
Choosing the right Design Pattern
I've always recognized the importance of utilizing design patterns. I'm curious as to how other developers go about choosing the most appropriate one. Do you use a series of characteristics (like a ...
144
votes
31
answers
151k
views
How do you dive into large code bases?
What tools and techniques do you use for exploring and learning an unknown code base?
I am thinking of tools like grep, ctags, unit-tests, functional test, class-diagram generators, call graphs, ...
41
votes
2
answers
17k
views
What is O(...) and how do I calculate it?
Help! I have a question where I need to analyze the Big-O of an algorithm or some code.
I am unsure exactly what Big-O is or how it relates to Big-Theta or other means of analyzing an algorithm's ...
30
votes
4
answers
10k
views
Style for control flow with validation checks
I find myself writing a lot of code like this:
int myFunction(Person* person) {
int personIsValid = !(person==NULL);
if (personIsValid) {
// do some stuff; might be lengthy
int myresult ...
176
votes
17
answers
18k
views
How can I convince management to deal with technical debt?
This is a question that I often ask myself when working with developers. I've worked at four companies so far and I've become aware of a lack of attention to keeping code clean and dealing with ...
424
votes
17
answers
173k
views
Why is Global State so Evil?
Before we start this, let me say I'm well aware of the concepts of Abstraction and Dependency Injection. I don't need my eyes opened here.
Well, most of us say, (too) many times without really ...
2183
votes
1
answer
481k
views
What technical details should a programmer of a web application consider before making the site public?
What things should a programmer implementing the technical details of a web application consider before making the site public? If Jeff Atwood can forget about HttpOnly cookies, sitemaps, and cross-...
99
votes
34
answers
65k
views
"Comments are a code smell" [closed]
A coworker of mine believes that any use of in-code comments (ie, not javadoc style method or class comments) is a code smell. What do you think?
31
votes
3
answers
60k
views
Approaches for checking multiple conditions? [duplicate]
What is the best practice for checking multiple conditions, in no particular order?
The example in question needs to check four distinct conditions, in any order, and fail showing the correct error ...
325
votes
25
answers
76k
views
When is a BIG Rewrite the answer?
Just read the question about the Big Rewrites and I remembered a question that I've been wanting answered myself.
I have a horrible project passed down to me, written in old Java, using Struts 1.0, ...
125
votes
7
answers
15k
views
What is the most effective way to add functionality to unfamiliar, structurally unsound code? [duplicate]
This is probably something everyone has to face during the development sooner or later.
You have an existing code written by someone else, and you have to extend it to work under new requirements.
...
197
votes
4
answers
90k
views
What is an Anti-Corruption layer, and how is it used?
I'm trying to figure out what the Anti-Corruption layer really means. I know that it's a way to transition/work around legacy code or bad APIs. What I don't understand is how it works and what makes ...
33
votes
3
answers
11k
views
How to tackle a 'branched' arrow head anti-pattern? [duplicate]
I recently read this question that features, the arrow anti-pattern.
I have something similar in code I'm trying to refactor except that it branches. It looks a little something like this:
if(...
80
votes
2
answers
13k
views
Are there any OO-principles that are practically applicable for Javascript?
Javascript is a prototype-based object oriented language but can become class-based in a variety of ways, either by:
Writing the functions to be used as classes by yourself
Use a nifty class system ...
202
votes
14
answers
140k
views
When are Getters and Setters Justified?
Getters and setters are often criticized as being not proper OO. On the other hand, most OO code I've seen has extensive getters and setters.
When are getters and setters justified? Do you try to ...
38
votes
9
answers
11k
views
How to determine if a class meets the single responsibility principle?
The Single Responsibility Principle is based on the high cohesion principle. The difference between the two is that a highly cohesive classes features a set of responsibilities that are strongly ...
91
votes
13
answers
32k
views
To branch or not to branch?
Till recently my development workflow was the following:
Get the feature from product owner
Make a branch (if feature is more than 1 day)
Implement it in a branch
Merge changes from main branch to my ...
283
votes
6
answers
165k
views
Choosing between Single or multiple projects in a git repository?
In a git environment, where we have modularized most projects, we're facing the one project per repository or multiple projects per repository design issue. Let's consider a modularized project:
...
140
votes
16
answers
13k
views
How can I tactfully suggest improvements to others' badly designed code during review?
I'm a great believer in clean code and code craftsmanship, though I'm currently at a job where this isn't regarded as a top priority. I sometimes find myself in a situation where a peer's code is ...
202
votes
10
answers
134k
views
Are exceptions as control flow considered a serious antipattern? If so, Why?
Back in the late 90's I worked quite a bit with a code base that used exceptions as flow control. It implemented a finite state machine to drive telephony applications. Lately I am reminded of those ...
138
votes
5
answers
69k
views
Why should I prefer composition over inheritance?
I always read that composition is to be preferred over inheritance. A blog post on unlike kinds, for example, advocates using composition over inheritance, but I can't see how polymorphism is achieved....
104
votes
10
answers
12k
views
Where is the line between unit testing application logic and distrusting language constructs?
Consider a function like this:
function savePeople(dataStore, people) {
people.forEach(person => dataStore.savePerson(person));
}
It might be used like this:
myDataStore = new Store('some ...
4
votes
2
answers
9k
views
How should I test the functionality of a function that uses other functions in it? [duplicate]
Suppose there is a function get-data which returns a map of information about the id of the user passed in. Now this function uses 3 functions source-a, source-b and source-c to get three different ...
297
votes
14
answers
444k
views
How do you unit test private methods?
I am working on a java project. I am new to unit testing. What is the best way to unit test private methods in java classes?
179
votes
13
answers
78k
views
Is it OK to split long functions and methods into smaller ones even though they won't be called by anything else? [duplicate]
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 ...
59
votes
12
answers
35k
views
How Do Computers Work? [closed]
This is almost embarrassing ask...I have a degree in Computer Science (and a second one in progress). I've worked as a full-time .NET Developer for nearly five years. I generally seem competent at ...
1642
votes
11
answers
823k
views
Which hashing algorithm is best for uniqueness and speed?
Which hashing algorithm is best for uniqueness and speed? Example (good) uses include hash dictionaries.
I know there are things like SHA-256 and such, but these algorithms are designed to be secure,...
71
votes
5
answers
14k
views
Do I need unit test if I already have integration test?
If I already have integration test for my program, and they all passed, then I have a good feel that it will work. Then what are the reasons to write/add unit tests? Since I already have to write ...
63
votes
8
answers
21k
views
What is the "default" software license?
If I release some code and binaries, but I don't include any license at all with it, what are the legal terms that apply by default (in the US, where I am). I know that I automatically have copyright ...
175
votes
24
answers
114k
views
Elegant ways to handle if(if else) else
This is a minor niggle, but every time I have to code something like this, the repetition bothers me, but I'm not sure that any of the solutions aren't worse.
if(FileExists(file))
{
contents = ...
284
votes
6
answers
322k
views
Can I use GPL software in a commercial application
I have 3 questions about the GPL here:
If I use GPL software in my application, but don't modify or distribute it, do I have to release my application under the GPL?
What if I modify some software ...
45
votes
12
answers
15k
views
Dealing with bad/incomplete/unclear specifications? [duplicate]
I'm working on a project where our dev team gets the specifications from the business part of the company. Both the business management and the IT management require estimates and deadline projections,...
35
votes
6
answers
9k
views
Should I extract specific functionality into a function and why?
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 ...
709
votes
17
answers
248k
views
How to respond when you are asked for an estimate?
We, as programmers, are constantly being asked 'How long will it take'?
And you know, the situation is almost always like this:
The requirements are unclear. Nobody has done an in depth analysis of ...
302
votes
19
answers
227k
views
Should I return from a function early or use an if statement? [closed]
I've often written this sort of function in both formats, and I was wondering if one format is preferred over another, and why.
public void SomeFunction(bool someCondition)
{
if (someCondition)
...
28
votes
7
answers
22k
views
Refactoring Switch Statements and is there any real use for Switch Statements at all?
I was reading this article and was wondering, do we get rid of all switch statements by replacing them with a Dictionary or a Factory so that there are no switch statements at all in my projects.
...
57
votes
12
answers
7k
views
Develop fast and buggy, then correct errors or be slow, careful for each line of code? [duplicate]
Possible Duplicates:
Frankly, do you prefer Cowboy coding?
Prototyping vs. Clean Code at the early stages
Good design: How much hackyness is acceptable?
Does craftsmanship pay off?
Which is ...
46
votes
8
answers
12k
views
What is the real responsibility of a class?
I keep wondering if it is legitimate to use verbs that are based on nouns in OOP.
I came across this brilliant article, though I still disagree with the point it makes.
To explain the problem a bit ...
71
votes
8
answers
22k
views
How do you encode Algebraic Data Types in a C#- or Java-like language?
There are some problems which are easily solved by Algebraic Data Types, for example a List type can be very succinctly expressed as:
data ConsList a = Empty | ConsCell a (ConsList a)
consmap f ...
63
votes
9
answers
18k
views
Should a developer also act as a tester? [closed]
We're a scrum team of 3 developers, 1 designer, the scrum master, and the product owner. However, we don't have official tester in our team. A problem that is always with us, is that, testing the ...
24
votes
7
answers
5k
views
Rule of thumb for cost vs. savings for code re-use [duplicate]
Is it a good rule of thumb to always write code for the intent of re-using it somewhere down the road? Or, depending on the size of the component you are writing, is it better practice to design it ...
1334
votes
14
answers
268k
views
Where did the notion of "one return only" come from?
I often talk to programmers who say "Don't put multiple return statements in the same method." When I ask them to tell me the reasons why, all I get is "The coding standard says so." or "It's ...
294
votes
17
answers
103k
views
Is premature optimization really the root of all evil?
A colleague of mine today committed a class called ThreadLocalFormat, which basically moved instances of Java Format classes into a thread local, since they are not thread safe and "relatively ...
71
votes
5
answers
16k
views
When is Singleton appropriate? [duplicate]
There is a widely accepted opinion that Singleton is an anti-pattern. As usual, there are always exceptions to the rule. Can you explain why Singleton is a bad choice in general and give an example of ...
24
votes
4
answers
12k
views
Make methods that do not depend on instance fields, static?
Recently I started programming in Groovy for a integration testing framework, for a Java project. I use Intellij IDEA with Groovy plug-in and I am surprised to see as a warning for all the methods ...
155
votes
15
answers
48k
views
Where does this concept of "favor composition over inheritance" come from?
In the last few months, the mantra "favor composition over inheritance" seems to have sprung up out of nowhere and become almost some sort of meme within the programming community. And every time I ...
123
votes
9
answers
28k
views
Are design patterns really essential nowadays?
I was reading "Coders at Work" and have faced the fact that some of the professionals interviewed in the book are not so enthusiastic about design patterns.
I think that there are 2 main reasons for ...