Top "Idioms" questions

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

DRY Ruby Initialization with Hash Argument

I find myself using hash arguments to constructors quite a bit, especially when writing DSLs for configuration or other bits …

ruby initialization dry idioms
Get the first element of a list idiomatically in Groovy

Let the code speak first def bars = foo.listBars() def firstBar = bars ? bars.first() : null def firstBarBetter = foo.listBars()?.getAt(0) …

list groovy idioms
idioms for returning multiple values in shell scripting

Are there any idioms for returning multiple values from a bash function within a script? http://tldp.org/LDP/abs/…

shell idioms
Convert rune to int?

In the following code, I iterate over a string rune by rune, but I'll actually need an int to perform …

go type-conversion idioms rune
Idiomatic way of handling nullable or empty List in Kotlin

Say I have a variable activities of type List<Any>?. If the list is not null and not …

kotlin idioms kotlin-null-safety
Using nnet for prediction, am i doing it right?

I'm still pretty new to R and AI / ML techniques. I would like to use a neural net for prediction, …

r machine-learning neural-network idioms
Kotlin and idiomatic way to write, 'if not null, else...' based around mutable value

Suppose we have this code: class QuickExample { fun function(argument: SomeOtherClass) { if (argument.mutableProperty != null ) { doSomething(argument.mutableProperty) } else { doOtherThing() } } …

android kotlin idioms
Python "Every Other Element" Idiom

I feel like I spend a lot of time writing code in Python, but not enough time creating Pythonic code. …

python idioms
Idiomatic Python: 'times' loop

Say I have a function foo that I want to call n times. In Ruby, I would write: n.times { …

python loops idioms
when to use if vs elif in python

If I have a function with multiple conditional statements where every branch gets executed returns from the function. Should I …

python conditional idioms