Skip to main content

Questions tagged [programming-practices]

Programming Practices are the commonly or not so commonly used practices in development of software. These can include things like Agile Development, Kanban, Coding shortcuts, etc.

Filter by
Sorted by
Tagged with
309 votes
16 answers
136k views

Why are shortcuts like x += y considered good practice?

I have no idea what these are actually called, but I see them all the time. The Python implementation is something like: x += 5 as a shorthand notation for x = x + 5. But why is this considered good ...
295 votes
16 answers
30k views

Grokking Java culture - why are things so heavy? What does it optimize for? [closed]

I used to code in Python a lot. Now, for work reasons, I code in Java. The projects I do are rather small, and possibly Python would work better, but there are valid non-engineering reasons to use ...
Mikhail Ramendik's user avatar
283 votes
6 answers
167k 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
276 votes
14 answers
124k views

Should we avoid object creation in Java?

I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible. This seems somewhat to defeat ...
Slamice's user avatar
  • 2,657
251 votes
16 answers
49k views

What's wrong with comments that explain complex code?

A lot of people claim that "comments should explain 'why', but not 'how'". Others say that "code should be self-documenting" and comments should be scarce. Robert C. Martin claims that (rephrased to ...
Aviv Cohn's user avatar
  • 21.4k
244 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 ...
solidsnake's user avatar
  • 2,035
237 votes
17 answers
133k views

Torvalds' quote about good programmer [closed]

Accidentally I've stumbled upon the following quote by Linus Torvalds: "Bad programmers worry about the code. Good programmers worry about data structures and their relationships." I've thought ...
191 votes
15 answers
39k views

Why are the sizes of programs so large?

If we look at the vintage program Netscape Navigator or an early version of Microsoft Word, those programs were less than 50 MB in size. Now when I install google chrome it is 200 MB and desktop ...
Niklas Rosencrantz's user avatar
187 votes
17 answers
16k views

How do you balance between "do it right" and "do it ASAP" in your daily work? [closed]

I find myself pondering over this question from time to time, again and again. I want to do things the right way: to write clean, understandable and correct code that is easy to maintain. However, ...
Flot2011's user avatar
  • 2,192
187 votes
2 answers
225k views

Git branching and tagging best practices

I am currently learning to use Git by reading Pro Git. Right now I'm learning about branching and tags. My question is when should I use a branch and when should I use a tag? For example, say I ...
Code-Guru's user avatar
  • 2,449
184 votes
17 answers
25k views

Is there a benefit in compiling your code as you go along?

I recently had a job interview in which they gave me an hour to write some real code. It wasn't a huge amount, probably less than 100 lines. After about 45 minutes, I compiled, ran it, and got it to ...
CaptainCodeman's user avatar
153 votes
22 answers
26k views

Stuck due to "knowing too much" [closed]

Note more discussion at http://news.ycombinator.com/item?id=4037794 I have a relatively simple development task, but every time I try to attack it, I end up spiraling in deep thoughts - how could it ...
139 votes
5 answers
164k views

Two HTML elements with same id attribute: How bad is it really?

Just browsing the google maps source code. In their header, they have 2 divs with id="search" one contains the other, and also has jstrack="1" attribute. There is a form separating them like so: <...
danludwig's user avatar
  • 1,758
138 votes
17 answers
15k 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 ...
Koray Tugay's user avatar
  • 1,585
135 votes
10 answers
105k views

Why do most of us use 'i' as a loop counter variable?

Has anyone thought about why so many of us repeat this same pattern using the same variable names? for (int i = 0; i < foo; i++) { // ... } It seems most code I've ever looked at uses i, j, k ...
134 votes
14 answers
22k views

Should the solution be as generic as possible or as specific as possible?

Say I have a entity that has "type" attribute. There could be 20+ possible types. Now I'm asked to implement something that would allow changing the type from A->B, which is the only use case. So ...
LoveProgramming's user avatar
133 votes
19 answers
16k views

Can a function be too short?

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 ...
131 votes
15 answers
29k views

Are single-character constants better than literals?

I recently encountered a class which provides pretty much every single-character as a constant; everything from COMMA to BRACKET_OPEN. Wondering whether this was necessary; I read an "article" which ...
Austin Day's user avatar
  • 1,361
130 votes
11 answers
33k views

How has an increase in the complexity of systems affected successive generations of programmers?

As a "new" programmer (I first wrote a line of code in 2009), I've noticed it's relatively easy to create a program that exhibits quite complex elements today with things like .NET framework for ...
Adam 's user avatar
  • 1,397
127 votes
6 answers
163k views

Method vs Function vs Procedure

Simple question, but I often hear these three terms defined with such ferocity, but which have been known to me to mean different things over the years. What are the "correct" definitions of "...
Django Reinhardt's user avatar
126 votes
27 answers
10k views

What are the worst false economies in software development? [closed]

What are the worst false economies (that is ways of saving money that ultimately cost more than they save) prevalent in the software industry and how do you combat them?
123 votes
12 answers
47k views

Why are multiple programming languages used in the development of one product or piece of software?

I am a recent grad student aiming to start my Master's in Computer Science. I have come across multiple open source projects that really intrigue me and encourage me to contribute to them (CloudStack, ...
Parth Patel's user avatar
  • 1,029
118 votes
16 answers
24k views

Should I add redundant code now just in case it may be needed in the future?

Rightly or wrongly, I'm currently of the belief that I should always try to make my code as robust as possible, even if this means adding in redundant code / checks that I know won't be of any use ...
KidCode's user avatar
  • 2,183
112 votes
22 answers
134k views

Automatic programming: write code that writes code [closed]

After reading the book The Pragmatic Programmer, one of the arguments I found most interesting was "write code that writes code". I tried searching over the net for some more explanations or articles ...
105 votes
47 answers
76k views

Make a big deal out of == true?

There is a colleague of mine who constantly writes: if (someBool == true) It drives me up the wall! Should I make a big deal of it or just drop it?
105 votes
15 answers
120k views

Why are data structures so important in interviews? [closed]

I must confess that I was not so strong in data structures when I graduated out of college. Throughout the campus placements during my graduation, I've witnessed that most of the biggie tech companies ...
100 votes
3 answers
111k views

Break on default case in switch

I am a bit puzzled on whenever or not to include break after the last case, often default. switch (type) { case 'product': // Do behavior break; default: // Do ...
Robin Castlin's user avatar
98 votes
45 answers
29k views

What popular "best practices" are not always best, and why? [closed]

"Best practices" are everywhere in our industry. A Google search on "coding best practices" turns up nearly 1.5 million results. The idea seems to bring comfort to many; just follow the instructions,...
97 votes
53 answers
10k views

Harmful temptations in programming

Just curious, what kinds of temptations in programming turned out to be really harmful in your projects? Like when you really feel the urge to do something and you believe it's going to benefit the ...
96 votes
13 answers
13k views

How to warn other programmers of class implementation

I'm writing classes that "must be used in a specific way" (I guess all classes must...). For example, I create the fooManager class, which requires a call to, say, Initialize(string,string). ...
Gil Sand's user avatar
  • 2,183
94 votes
9 answers
17k views

Over thinking development

I've been working as an app developer for a year and a half now (not long I know), and I've just been given my first big project. Needless to say it didn't go very smoothly, so I sought advice from a ...
sf13579's user avatar
  • 1,060
94 votes
14 answers
9k views

How can I avoid always feeling like if I completely rebuilt my program from scratch I'd do it much better? [closed]

I have learned a significant amount of coding, however, it's always been in a scientific environment (not computer science), completely self-taught without anyone to guide me in the right direction. ...
Ashish's user avatar
  • 359
93 votes
7 answers
16k views

Short circuit evaluation, is it bad practice?

Something that I've known for a while but never considered is that in most languages it is possible to give priority to operators in an if statement based on their order. I often use this as a way to ...
innova's user avatar
  • 1,041
90 votes
12 answers
9k views

How big does my project need to be for me to unit test it? [closed]

I assume that my project is decoupled enough to allow for unit testing. But how big, exactly, in terms of clases and functions does my project need to be to make unit testing worthwhile? We all make ...
Lamin Sanneh's user avatar
  • 4,045
88 votes
11 answers
18k views

Is it a bad practice to modify code strictly for testing purposes

I have a debate with a programmer colleague about whether it is a good or bad practice to modify a working piece of code only to make it testable (via unit tests for example). My opinion is that it ...
liortal's user avatar
  • 1,175
87 votes
17 answers
6k views

Are my negative internship experiences representative of the real world? [closed]

I'm curious if my current experiences as an intern are representative of actual industry. As background, I'm through the better part of two computing majors and a math major at a major university; I'...
87 votes
10 answers
109k views

How many lines per class is too many in Java? [closed]

In your experience, what is a useful rule of thumb for how many lines of code are too many for one class in Java? To be clear, I know that number of lines is not even close to the real standard to ...
Michael McGowan's user avatar
85 votes
11 answers
12k views

Shouldn't unit tests use my own methods?

Today I was watching a "JUnit basics" video and the author said that when testing a given method in your program, you shouldn't use other of your own methods in the process. To be more specific, he ...
carlossierra's user avatar
  • 1,405
85 votes
8 answers
16k views

Is it okay to not completely understand code functionality? [duplicate]

As I am currently struggling with learning WCF for a project at work, for the past several days I have been looking at online tutorials and examples on the best way to make a WCF client; and today, ...
Ana Ameer's user avatar
  • 785
84 votes
8 answers
72k views

Is modifying an incoming parameter an antipattern? [closed]

I am programming in Java, and I always make converters sort of like this: public OtherObject MyObject2OtherObject(MyObject mo){ ... Do the conversion return otherObject; } At the new ...
CsBalazsHungary's user avatar
81 votes
15 answers
62k views

Is it possible to reach absolute zero bug state for large scale software?

I am talking about 20-30+ millions lines of code, software at the scale and complexity of Autodesk Maya for example. If you freeze the development as long as it needs to be, can you actually fix all ...
Joan Venge's user avatar
  • 1,970
81 votes
7 answers
21k views

Code First vs. Database First

When I design and create the software I work on, I typically design and create the back-end SQL tables first and then move on to the actual programming. The project I'm currently working on has me ...
RubberDuck's user avatar
  • 8,981
79 votes
11 answers
16k views

Does programming in general become easier to read, write and understand as you gain experience? [closed]

I'm a beginner in programming and I've been reading books, studying, reading articles, and whatnot. I'm getting great results since I've started learning programming, and when I was a beginner I used ...
Bugster's user avatar
  • 4,023
79 votes
17 answers
11k views

How to train yourself to avoid writing “clever” code? [closed]

Do you know that feeling when you just need to show off that new trick with Expressions or generalize three different procedures? This does not have to be on Architecture Astronaut scale and in fact ...
73 votes
11 answers
28k views

When to commit code?

When working on a project, the code may be developed reasonably fast in a single day or bit by bit for a prolonged period of few weeks/months/years. As code commits are becoming to be considered as a ...
user avatar
68 votes
17 answers
23k views

How to write correct loops?

Most of time while writing loops I usually write wrong boundary conditions(eg: wrong outcome) or my assumptions about loop terminations are wrong(eg: infinitely running loop). Although I got my ...
CodeYogi's user avatar
  • 2,176
68 votes
16 answers
68k views

Best practice on if/return

I want to know what is considered better way of returning when I have if statement. Example 1: public bool MyFunction() { // Get some string for this example string myString = GetString(); ...
68 votes
8 answers
8k views

If I need to use a piece of memory throughout the lifespan of my program, is it really necessary to free it right before program termination?

In many books and tutorials, I've heard the practice of memory management stressed and felt that some mysterious and terrible things would happen if I didn't free memory after I'm done using it. I ...
CaptainObvious's user avatar
66 votes
10 answers
35k views

Is there such a thing as having too many private functions/methods?

I understand the importance of well documented code. But I also understand the importance of self-documenting code. The easier it is to visually read a particular function, the faster we can move on ...
Sal Rahman's user avatar
  • 1,544
64 votes
7 answers
25k views

Can too much abstraction be bad?

As programmers I feel that our goal is to provide good abstractions on the given domain model and business logic. But where should this abstraction stop? How to make the trade-off between abstraction ...
Random42's user avatar
  • 10.5k

1
2 3 4 5
32