Most Popular

1500 questions
135
votes
15 answers

Is it always a best practice to write a function for anything that needs to repeat twice?

Myself, I can't wait to write a function when I need to do something more than twice. But when it comes to things that only appear twice, it's a bit more tricky. For code that needs more than two lines, I'll write a function. But when facing things…
Zen
  • 1,693
135
votes
6 answers

What does it mean when data is scalar?

I don't know what scalar means exactly, but I'm trying to see if I'm thinking about it correctly. Does scalar relate to arbitrariness where the type of data could be any type, or a system is not able to know what the data is in advance.
Ryan
  • 1,479
135
votes
10 answers

Relationship between user story, feature, and epic?

As someone who's still new to agile, I'm not sure I completely understand the relationship or difference between user story, feature, and epic. According to this question, a feature is a collection of stories. One of the answers suggests that a…
nivlam
  • 2,840
135
votes
10 answers

What is the opposite of initialize (or init)?

The term will be used as a method name. The method is called when a part of the user interface is hidden (or removed), and it is used to reset values to default and dispose objects that will not be used any more. Possible names are: release, remove,…
134
votes
8 answers

What does C++ do better than D?

I have recently been learning D and am starting to get some sort of familiarity with the language. I know what it offers, I don't yet know how to use everything, and I don't know much about D idioms and so on, but I am learning. I like D. It is a…
Anto
  • 11,187
  • 13
  • 68
  • 103
134
votes
25 answers

Is it "normal" for people to not work?

After graduating from college I was hired as a junior programmer a little over a year ago. I quickly noticed that I was degrees of magnitude faster than all the other programmers; this seems to be because I simply don't waste time "in general". The…
user27112
  • 403
  • 2
  • 5
  • 5
134
votes
5 answers

In Java, should I use "final" for parameters and locals even when I don't have to?

Java allows marking variables (fields / locals / parameters) as final, to prevent re-assigning into them. I find it very useful with fields, as it helps me quickly see whether some attributes - or an entire class - are meant to be immutable. On the…
Oak
  • 5,245
134
votes
7 answers

Are private, unguessable URLs equivalent to password-based authentication?

I want to expose a resource on the web. I want to protect this resource: to make sure it is only accessible to certain individuals. I could set up some kind of password-based authentication. For example, I could only allow access to the resource…
133
votes
13 answers

(Why) is it important that a unit test not test dependencies?

I understand the value of automated testing and use it wherever the problem is well-specified enough that I can come up with good test cases. I've noticed, though, that some people here and on StackOverflow emphasize testing only a unit, not its…
dsimcha
  • 17,234
133
votes
19 answers

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 sometimes end up with one or two line functions such…
133
votes
14 answers

Why do most programming languages only support returning a single value from a function?

Is there a reason why functions in most(?) programming languages are designed to support any number of input parameters but only one return value? In most languages, it is possible to "work around" that limitation, e.g. by using out-parameters,…
M4N
  • 1,447
133
votes
17 answers

How do you store "fuzzy dates" into a database?

This is a problem I've run into a few times. Imagine you have a record that you want to store into a database table. This table has a DateTime column called "date_created". This one particular record was created a long time ago, and you're not…
nbv4
  • 1,562
133
votes
6 answers

Difference between a socket and a port

Could someone please explain quite clearly the difference between a port and a socket. I know that a port serves as a door into the network for an application process and that the application process uses a socket connection to the given port…
cobie
  • 3,237
132
votes
8 answers

Is it better to document functions in the header file or the source file?

In languages that distinguish between a "source" and "header" file (mainly C and C++), is it better to document functions in the header file: (pilfered from CCAN) /** * time_now - return the current time * * Example: * printf("Now is %lu…
Joey Adams
  • 5,585
132
votes
15 answers

How do you write unit tests for code with difficult to predict results?

I frequently work with very numeric / mathematical programs, where the exact result of a function is difficult to predict in advance. In trying to apply TDD with this kind of code, I often find writing the code under test significantly easier than…