Questions tagged [design]
Questions about problem solving and planning for a solution through software design.
5,050
questions
286
votes
17
answers
97k
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 ...
246
votes
16
answers
21k
views
Project is nearly done, but procedural spaghetti code. Do I rewrite or just keep trying to ship it? [closed]
I'm a beginner web developer (one year of experience).
A couple of weeks after graduating, I got offered a job to build a web application for a company whose owner is not much of a tech guy. He ...
244
votes
15
answers
159k
views
Is it wrong to use a boolean parameter to determine behavior?
I have seen a practice from time to time that "feels" wrong, but I can't quite articulate what is wrong about it. Or maybe it's just my prejudice. Here goes:
A developer defines a method with a ...
231
votes
17
answers
91k
views
Is it good practice to always have an autoincrement integer primary key?
In my databases, I tend to get into the habit of having an auto-incrementing integer primary key with the name id for every table I make so that I have a unique lookup for any particular row.
Is this ...
217
votes
18
answers
108k
views
How can one manage thousands of IF...THEN...ELSE rules?
I am considering building an application, which, at its core, would consist of thousands of if...then...else statements. The purpose of the application is to be able to predict how cows move around in ...
212
votes
5
answers
47k
views
What are good habits for designing command line arguments?
While developing the application I started to wonder - How should I design command line arguments?
A lot of programs are using formula like this -argument value or /argument value. Solution which ...
193
votes
7
answers
119k
views
How do searches fit into a RESTful interface?
When designing a RESTful interface, the semantics of the request types are deemed vital to the design.
GET - List collection or retrieve element
PUT - Replace collection or element
POST - Create ...
183
votes
5
answers
176k
views
When do you use a struct instead of a class? [closed]
What are your rules of thumb for when to use structs vs. classes? I'm thinking of the C# definition of those terms but if your language has similar concepts I'd like to hear your opinion as well.
I ...
173
votes
21
answers
20k
views
How do quick & dirty programmers know they got it right?
If you ask programmers why they should write clean code, the number one answer you get is maintainability. While that's on my list, my main reason is more immediate and less altruistic: I can't tell ...
150
votes
8
answers
24k
views
Are bad programming practices typical within the software industry? [closed]
I just started my first job as a software developer over a month ago. Everything I have learned about OOP, SOLID, DRY, YAGNI, design patterns, SRP, etc. can be thrown out the window.
They use C# .NET ...
149
votes
12
answers
26k
views
Is this a violation of the Liskov Substitution Principle?
Say we have a list of Task entities, and a ProjectTask sub type. Tasks can be closed at any time, except ProjectTasks which cannot be closed once they have a status of Started. The UI should ensure ...
147
votes
14
answers
114k
views
What is the ideal length of a method for you? [closed]
In object-oriented programming, there is of course no exact rule on the maximum length of a method , but I still found these two quotes somewhat contradicting each other, so I would like to hear what ...
143
votes
8
answers
9k
views
How do I get people to stop bikeshedding (focusing on trivialities)?
I have been tasked with teaching other teams a new codebase, but I keep running into an issue. Whenever I go to actually walk through the code with people, we don't get very far before the entire ...
138
votes
17
answers
14k
views
How do I know how reusable my methods should be? [closed]
I am minding my own business at home and my wife comes to me and says
Honey.. Can you print all the Day Light Savings around the world for 2018 in the console? I need to check something.
And I am ...
129
votes
11
answers
38k
views
The modern way to perform error handling...
I've been pondering this problem for a while now and find myself continually finding caveats and contradictions, so I'm hoping someone can produce a conclusion to the following:
Favour exceptions over ...
123
votes
9
answers
27k
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 ...
109
votes
12
answers
18k
views
Is testable code better code?
I'm attempting to get into the habit of writing unit tests regularly with my code, but I've read that first it's important to write testable code.
This question touches on SOLID principles of writing ...
98
votes
7
answers
33k
views
Should I use Dependency Injection or static factories?
When designing a system I am often faced with the problem of having a bunch of modules (logging, database acces, etc) being used by the other modules. The question is, how do I go about providing ...
96
votes
6
answers
26k
views
Why are some C programs written in one huge source file?
For example, the SysInternals tool "FileMon" from the past has a kernel-mode driver whose source code is entirely in one 4,000-line file. The same for the first ever ping program ever written (~2,000 ...
94
votes
17
answers
25k
views
Is it a good idea to design an architecture thinking that the User Interface classes can be replaced by a command line interface?
In Code Complete page 25, it's said that it's a good idea to be able to easily replace the regular user interface classes by a command line one.
Knowing its advantages for testing, what about the ...
94
votes
11
answers
11k
views
Why should main() be short?
I've been programming for over 9 years, and according to the advice of my first programming teacher, I always keep my main() function extremely short.
At first I had no idea why. I just obeyed ...
93
votes
6
answers
130k
views
Difference between a service class and a Helper class [closed]
I would like to know what differentiates a Service class from a utility class or a helper class?
A class only with underlying methods calls the dao's is a service? Doesn't the usage of Helper ...
91
votes
8
answers
16k
views
What is "Soft Coding", really?
In this article by Alex Papadimoulis, you can see this snippet:
private void attachSupplementalDocuments()
{
if (stateCode == "AZ" || stateCode == "TX") {
//SR008-04X/I are always required in ...
91
votes
8
answers
98k
views
Why would you store an enum in DB?
I've seen a number of questions, like this, asking for advice on how to store enums in DB. But I wonder why would you do that. So let's say that I have an entity Person with a gender field, and a ...
87
votes
9
answers
12k
views
I can write code... but can't design well. Any suggestions? [closed]
I feel that I am good at writing code in bits and pieces, but my designs really suck. The question is, how do I improve my designs - and in turn become a better designer?
I think schools and colleges ...
86
votes
18
answers
5k
views
Design flaws and dealing with humiliation from it [closed]
Have you always been fundamentally correct in the software designs you proposed? When you give out some design that was fundamentally wrong, you tend to lose the respect of your fellow team members. ...
86
votes
22
answers
13k
views
Is OOP hard because it is not natural?
One can often hear that OOP naturally corresponds to the way people think about the world. But I would strongly disagree with this statement: We (or at least I) conceptualize the world in terms of ...
85
votes
3
answers
33k
views
What is REST (in simple English) [closed]
Lately I have become interested in familiarizing myself with REST. I tried reading wiki entry on REST, but it was of no help. I would really appreciate it if someone can explain in simple English (...
84
votes
7
answers
207k
views
Designing a REST api by URI vs query string
Let's say I have three resources that are related like so:
Grandparent (collection) -> Parent (collection) -> and Child (collection)
The above depicts the relationship among these resources ...
83
votes
12
answers
52k
views
What's actually wrong with an endpoint returning HTML rather than JSON data?
When I first started learning PHP (about 5 or 6 years ago) I learned about Ajax, and I went through "the phases":
Your server returns HTML data and you put it inside a DOM's innerHTML
You learn about ...
82
votes
11
answers
15k
views
Is DRY the enemy of software project management?
One of the most basic and widely accepted principles of software development is DRY (don't repeat yourself). It is also clear that most software projects require some kind of management.
Now what are ...
81
votes
12
answers
146k
views
SQL: empty string vs NULL value
I know this subject is a bit controversial and there are a lot of various articles/opinions floating around the internet. Unfortunatelly, most of them assume the person doesn't know what the ...
80
votes
4
answers
23k
views
Why do many software developers violate the open/closed principle?
Why do many software developers violate the open/closed principle by modifying many things like renaming functions which will break the application after upgrading?
This question jumps to my head ...
78
votes
7
answers
10k
views
How to manage accidental complexity in software projects
When Murray Gell-Mann was asked how Richard Feynman managed to solve so many hard problems Gell-Mann responded that Feynman had an algorithm:
Write down the problem.
Think real hard.
Write down the ...
78
votes
16
answers
5k
views
Should we design programs to randomly kill themselves? [closed]
In a nutshell, should we design death into our programs, processes, and threads at a low level, for the good of the overall system?
Failures happen. Processes die. We plan for disaster and ...
78
votes
16
answers
10k
views
How do I deal with analysis paralysis?
Very frequently, I am stuck when choosing the best design decision. Even for small details, such as function definitions, control flow, and variable names, I spend unusually long periods perusing the ...
76
votes
9
answers
68k
views
Why use partial classes?
In my understanding, the partial keyword does nothing but allow a class to be split between several source files. Is there any reason to do this other than for code organization? I've seen it used for ...
76
votes
14
answers
9k
views
Clarify the Single Responsibility Principle
The Single Responsibility Principle states that a class should do one and only one thing. Some cases are pretty clear cut. Others, though, are difficult because what looks like "one thing" when ...
75
votes
6
answers
13k
views
What should I consider when the DRY and KISS principles are incompatible?
The DRY principle sometimes forces the programmers to write complex, hard-to-maintain functions/classes. Code like this has a tendency to become more complex and harder to maintain over time. ...
73
votes
7
answers
10k
views
Should I follow the normal path or fail early?
From the Code Complete book comes the following quote:
"Put the normal case after the if rather than after the else"
Which means that exceptions/deviations from the standard path should be put in ...
73
votes
10
answers
8k
views
My proposed design is usually worse than my colleague's - how do I get better? [closed]
I have been programming for couple of years and am generally good when it comes to fixing problems and creating small-to-medium scripts, however, I'm generally not good at designing large scale ...
72
votes
7
answers
80k
views
When to use abstract classes instead of interfaces with extension methods in C#?
"Abstract class" and "interface" are similar concepts, with interface being the more abstract of the two. One differentiating factor is that abstract classes provide method implementations for derived ...
72
votes
6
answers
78k
views
Many small requests vs. few large requests (API Design)
I'm currently working on a project with an organization as follows:
Client - Gets data from the main server via REST api.
Server - Requests data from various other servers via third-party APIs
Third-...
71
votes
11
answers
6k
views
Advice on designing web application with a 40+ year lifetime
Scenario
Currently, I am apart of a health care project whose main requirement is to capture data with unknown attributes using user generated forms by health care providers. The second requirement ...
71
votes
9
answers
25k
views
Are classes with only a single (public) method a problem?
I am currently working on a software project that performs compression and indexing on video surveillance footage. The compression works by splitting background and foreground objects, then saving the ...
71
votes
9
answers
31k
views
Why not expose a primary key
In my education I have been told that it is a flawed idea to expose actual primary keys (not only DB keys, but all primary accessors) to the user.
I always thought it to be a security problem (...
70
votes
7
answers
25k
views
If functions have to do null checks before doing the intended behaviour is this bad design?
So I don't know if this is good or bad code design so I thought I better ask.
I frequently create methods that do data processing involving classes and I often do a lot of checks in the methods to ...
70
votes
12
answers
9k
views
"Everything is a Map", am I doing this right?
I watched Stuart Sierra's talk "Thinking In Data" and took one of the ideas from it as a design principle in this game I'm making. The difference is he's working in Clojure and I'm working in ...
69
votes
9
answers
28k
views
Can manager classes be a sign of bad architecture?
Lately I've begun to think that having lots of manager classes in your design is a bad thing. The idea hasn't matured enough for me to make a compelling argument, but here's a few general points:
I ...
69
votes
4
answers
8k
views
Why were Java collections implemented with "optional methods" in the interface?
During my first implementation extending the Java collection framework, I was quite surprised to see that the collection interface contains methods declared as optional. The implementer is expected ...