Skip to main content

All Questions

136votes
10answers
106kviews

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 ...
57votes
6answers
5kviews

Is making a small change, testing it, then "rinse and repeat", a bad habit?

I am a programmer with a number of years of experience. I realized I got a certain habit. I'm not sure whether it's really a bad habit or not. I get a list of tasks to perform for a solution, even ...
Mathematics's user avatar
50votes
8answers
17kviews

When is it appropriate to make a separate function when there will only ever be a single call to said function? [duplicate]

We are designing coding standards, and are having disagreements as to if it is ever appropriate to break code out into separate functions within a class, when those functions will only ever be called ...
David's user avatar
  • 1,899
45votes
6answers
14kviews

Is it better to check `c >= '0'` or `c >= 48`?

After a discussion with some my colleagues, I've a 'philosophical' question about how treat the char data type in Java, following the best practices. Suppose a simple scenario (obviously this is only ...
wyr0's user avatar
  • 585
41votes
11answers
8kviews

Is it bad habit not using interfaces? [closed]

I use interfaces rarely and find them common in others code. Also I create sub and super classes (while creating my own classes) rarely in my code. Is it a bad thing? Would you suggest changing this ...
jineesh joseph's user avatar
35votes
8answers
7kviews

Are assignments in the condition part of conditionals a bad practice?

Let's assume I want to write a function that concatenates two strings in C. The way I would write it is: void concat(char s[], char t[]){ int i = 0; int j = 0; while (s[i] != '\0'){ ...
Richard Smith's user avatar
34votes
8answers
15kviews

Is throwing an exception an anti-pattern here?

I just had a discussion over a design choice after a code review. I wonder what your opinions are. There's this Preferences class, which is a bucket for key-value pairs. Null values are legal (that'...
Konrad Morawski's user avatar
31votes
10answers
6kviews

Simple vs Complex (but performance efficient) solution - which one to choose and when?

I have been programming for a couple of years and have often found myself at a dilemma. There are two solutions - one is simple one i.e. simple approach, easier to understand and maintain. It ...
MoveFast's user avatar
18votes
7answers
27kviews

Why unused variables is such an issue?

I was cleaning unused variables warnings one day, and I started to ponder, what exactly is the problem about them? In fact, some of them even help in debugging (e.g. inspect exception details, or ...
Tar's user avatar
  • 307
18votes
7answers
8kviews

A defense for boilerplate?

To me, boilerplate code is obviously bad. However I've met a developer who displays resistance in any attempt to reduce boilerplate. I realized I didn't have a readily formed, well thought out ...
abstracted's user avatar
18votes
2answers
8kviews

Is there a standardized practice for ordering attributes in HTML tags?

I am working on an AngularJS project and the attributes are numerous in many of my HTML elements: <button type="submit" ng-click="Page.UI.DetailView.ExecuteFunction()" ng-...
Matt Cashatt's user avatar
15votes
9answers
2kviews

Should a programmer take writing lessons to enhance code expressiveness?

Given that programmers are authors and write code to express abstract thoughts and concepts, and good code should be read by other programmers without difficulties and misunderstandings, should a ...
Jose Faeti's user avatar
14votes
2answers
3kviews

Is it bad practice to create blocks of code?

In C++, is it bad practice create blocks of code inside some function, such as the following: bool f() { { double test = 0; test = // some other variable ...
Inertial Ignorance's user avatar
12votes
5answers
6kviews

Should I be using const more in C++?

There are some things I am pretty strict about, but const has not been one of them. For example, I might make a local variable that I use three times in a function, that does not get changed, and yet ...
Anon's user avatar
  • 3,633
11votes
4answers
606views

When should a private method take the public route to access private data?

When should a private method take the public route to access private data? For example, if I had this immutable 'multiplier' class (a bit contrived, I know): class Multiplier { public: Multiplier(...
0x5f3759df's user avatar

153050per page
close