Top "Idioms" questions

A programming idiom is the usual and customary way to write code in a particular language.

Check whether a variable is a string in Ruby

Is there anything more idiomatic than the following? foo.class == String

ruby idioms typechecking
Are one-line 'if'/'for'-statements good Python style?

Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one …

python for-loop if-statement idioms
Get dplyr count of distinct in a readable way

I'm new using dplyr, I need to calculate the distinct values in a group. Here's a table example: data=data.…

r dplyr idioms summarization
Finding an item that matches predicate in Scala

I'm trying to search a scala collection for an item in a list that matches some predicate. I don't necessarily …

scala collections idioms
C++ code for state machine

This was an interview question to be coded in C++: Write code for a vending machine: Start with a simple …

c++ design-patterns switch-statement state-machine idioms
Union of dict objects in Python

How do you calculate the union of two dict objects in Python, where a (key, value) pair is present in …

python dictionary associative-array idioms set-operations
`if key in dict` vs. `try/except` - which is more readable idiom?

I have a question about idioms and readability, and there seems to be a clash of Python philosophies for this …

python idioms readability defaultdict code-readability
Best ruby idiom for "nil or zero"

I am looking for a concise way to check a value to see if it is nil or zero. Currently …

ruby design-patterns idioms null
Named Parameter idiom in Java

How to implement Named Parameter idiom in Java? (especially for constructors) I am looking for an Objective-C like syntax and …

java idioms
Pairs from single list

Often enough, I've found the need to process a list by pairs. I was wondering which would be the pythonic …

python list zip slice idioms