Questions tagged [idioms]

A programming idiom is common way or pattern of writing code to solve a particular problem.

41 questions
44
votes
7 answers

What is idiomatic?

I understand an "idiom" to be a common operation or pattern that in a particular language is not simplified by core language syntax, such as integer increment: i = i + 1; In C++, this idiom is simplified by an operator: ++i; However, when someone…
void.pointer
  • 5,113
41
votes
10 answers

Difference between Idiom and Design Pattern?

What is the difference between idiom and design-pattern? It seems that these terminologies overlap somewhere; where exactly, I don't know. Are they interchangeable? When should I use what? Here is a list of C++ Idioms. Can I call them design…
32
votes
3 answers

What does 'opinionated software' really mean?

I've seen a lot of other framework/library developers throw the phrase 'we write opinionated software' around, but in practical terms, what does that really mean? Does it mean that the author of the 'Opinionated Framework X' says that because they…
plaureano
  • 1,241
24
votes
11 answers

Is it logical to not use inheritance because the function is critical?

Our codebase has a typical base-class with a ton of sub-classes. The base-class already has many default functions for the sub-classes. However, one particular function has the same verbatim implementation in almost all of the sub-classes. (Each of…
23
votes
3 answers

Is the purpose behind code being 'idiomatic' to reduce cognitive overhead?

I'm trying to explain to someone that the way they've written the code makes it hard to understand, and if you refactor it then it's easier to read. This style of code I'm driving at is commonly called 'idiomatic' code'. But the phrase idiomatic…
hawkeye
  • 4,859
17
votes
6 answers

Representing business rules with exceptions

I know it is expensive but (IMO) I believe it is a very good practice. I'm talking about rules like say, you can't save an Invoice if you are not a sales person... so in that case throwing an exception saying 'your are not authorized' or…
13
votes
5 answers

What problems can arise from emulating concepts from another languages?

I've read many times on the web that if your language doesn't support some concept, for example, object orientation, or maybe function calls, and it's considered a good practice in this other context, you should do it. The only problem I can see now…
9
votes
4 answers

C++ Iterator lifetime and detecting invalidation

Based on what's considered idiomatic in C++11: should an iterator into a custom container survive the container itself being destroyed? should it be possible to detect when an iterator becomes invalidated? are the above conditional on "debug…
DK.
  • 228
  • 1
  • 3
  • 7
8
votes
4 answers

log levels and stdout vs stderr

I'm writing an app which uses a logger with different logging levels (info, debug, warning, error, etc.); but - I'm used to the idiom of writing program output to stdout and error information to stderr. Suppose my logger uses all of these levels,…
einpoklum
  • 2,752
8
votes
2 answers

Pros and cons of branching when fixing old code

Sometimes I discover that a commit I made two months ago had a bug. So I write a fix for the bug, but then I must choose one these ways of committing it: I can commit the fix directly onto the main up-to-date branch (the trunk). I can use a branch…
8
votes
3 answers

Idiomaticy of macros in C++

Macros are considered a good thing by one and evil by another. Is there a rule of thumb when to and when not to use macros in C++? When are macros idiomatic and when should they be avoided?
Mast
  • 201
7
votes
6 answers

Coding style for chained function calls

A common thing you need to do is to take a value, do something with it by passing it to a function, and then do some more with the return value, in a chain. Whenever I run into this type of scenario, I get unsure about how best to write the code. As…
7
votes
5 answers

Filesystem like permissions for C++ type-members

Abstract (tl;dr) Please read the full question, this is awfully simplified: How can unix file permission style restrictions be applied to inter-type data/control flows, allowing fine-grained access to some class-members for some groups of…
6
votes
3 answers

When we say "sanity" when referring to user input, are we talking about the cleanliness of the input or whether or not it is sane?

I often hear people say they "sanitize input," which would mean make it clean. I understand this to mean "clean of potentially damaging contents," where the function that does the sanitizing would do something like character escaping. But then I…
Carson Myers
  • 2,480
  • 3
  • 24
  • 25
6
votes
4 answers

How does one learn to program (and think) the Ruby way?

Why I Ask this Question: I've just starting to learn Ruby (and by extension IronRuby since I work in the Microsoft world). I picked up IronRuby Unleased to teach me the basic syntax of Ruby, and any particulars of IronRuby. However, learning the…
1
2 3