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.

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.

Common Questions Include:

1574 questions
311
votes
16 answers

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 practice? I've run across it in nearly every book…
Fomite
  • 2,616
  • 6
  • 18
  • 20
295
votes
16 answers

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

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 Java (I can't go into details). Java syntax is no…
Mikhail Ramendik
  • 1,549
  • 2
  • 9
  • 11
282
votes
6 answers

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: myProject/ +-- gui +-- core +-- api +--…
Johan Sjöberg
  • 3,007
  • 4
  • 16
  • 7
275
votes
14 answers

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 the purpose of object oriented programming. If we…
Slamice
  • 2,647
  • 3
  • 14
  • 10
250
votes
16 answers

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 my own words) often "comments are apologies for…
Aviv Cohn
  • 21,190
  • 31
  • 118
  • 178
246
votes
16 answers

Project is nearly done, but procedural spaghetti code. Do I rewrite or just keep trying to ship it?

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 recruited me to avoid theft of his idea, the high cost…
237
votes
17 answers

Torvalds' quote about good programmer

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 about it for the last few days and I'm still…
beyeran
  • 1,052
  • 3
  • 8
  • 10
191
votes
15 answers

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 version of Slack is 300 MB. I read about some rule…
Niklas Rosencrantz
  • 8,008
  • 17
  • 56
  • 95
187
votes
17 answers

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

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, what I end up doing is writing patch upon a patch;…
185
votes
17 answers

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 work. I may have spent 5-10 minutes working out…
CaptainCodeman
  • 1,895
  • 2
  • 15
  • 14
184
votes
2 answers

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 create a branch for version 1.1 of a project. When I…
Code-Guru
  • 2,419
  • 3
  • 16
  • 17
154
votes
22 answers

Stuck due to "knowing too much"

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 extending the future, what are the 2nd generation…
Ran Biron
  • 457
  • 2
  • 5
  • 10
140
votes
5 answers

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:
138
votes
17 answers

How do I know how reusable my methods should be?

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 super happy because that was what I had been…
Koray Tugay
  • 1,565
  • 3
  • 12
  • 18
135
votes
10 answers

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 and so on as iteration variables. I suppose I picked…
kprobst
  • 641
  • 2
  • 6
  • 9
1
2 3
99 100