All Questions

Filter by
Sorted by
Tagged with
354 votes
19 answers
64k 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 ...
465 votes
19 answers
197k 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
46k 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
25k 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 ...
Carl Sagan's user avatar
144 votes
31 answers
153k 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
18k 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 ...
William Jockusch's user avatar
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 ...
Desolate Planet's user avatar
427 votes
18 answers
177k 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 ...
Madara's Ghost's user avatar
2182 votes
1 answer
483k 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
66k 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 ...
Redandwhite's user avatar
325 votes
25 answers
77k 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. ...
Coder's user avatar
  • 6,968
203 votes
4 answers
93k 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 ...
knownasilya's user avatar
  • 3,194
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(...
AncientSwordRage's user avatar
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 ...
Spoike's user avatar
  • 14.8k
202 votes
14 answers
141k 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 ...
user1483278's user avatar
  • 1,131
140 votes
5 answers
71k 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....
MustafaM's user avatar
  • 1,998
91 votes
13 answers
33k 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 ...
SiberianGuy's user avatar
  • 4,793
283 votes
6 answers
166k 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: ...
Johan Sjöberg's user avatar
140 votes
16 answers
14k 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 ...
Yony's user avatar
  • 1,657
5 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 ...
Amogh Talpallikar's user avatar
206 votes
10 answers
139k 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 ...
Aaron Anodide's user avatar
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 ...
Jonah's user avatar
  • 1,476
299 votes
14 answers
453k 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?
Vinoth Kumar C M's user avatar
179 votes
13 answers
79k 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 ...
Stas Bichenko's user avatar
74 votes
5 answers
15k 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 ...
Bryan Chen's user avatar
  • 1,095
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 ...
Rob P.'s user avatar
  • 823
1650 votes
11 answers
831k 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,...
Earlz's user avatar
  • 22.8k
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 ...
Tesserex's user avatar
  • 3,025
175 votes
24 answers
115k 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 = ...
289 votes
6 answers
329k 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 ...
Petah's user avatar
  • 3,441
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,...
eagerMoose's user avatar
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 ...
dhblah's user avatar
  • 1,381
709 votes
17 answers
249k 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
231k 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
23k 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. ...
Kanini's user avatar
  • 2,248
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 ...
Francesco Boffa's user avatar
46 votes
8 answers
13k 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 ...
Pierre Arlaud's user avatar
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 ...
Jörg W Mittag's user avatar
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 ...
Saeed Neamati's user avatar
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 ...
Tyler's user avatar
  • 789
1342 votes
14 answers
270k 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 ...
296 votes
17 answers
106k 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 ...
72 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 ...
Fishtoaster's user avatar
  • 25.9k
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 ...
Random42's user avatar
  • 10.4k
157 votes
15 answers
49k 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 ...
124 votes
9 answers
29k 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 ...
Sergey's user avatar
  • 2,703

15 30 50 per page
1
2 3 4 5
127