Top "Idioms" questions

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

PHP - best way to initialize an object with a large number of parameters and default values

I'm designing a class that defines a highly complex object with a ton (50+) of mostly optional parameters, many of which …

php class constructor instantiation idioms
The preferred way to set matplotlib figure/axes properties

Say I have a matplotlib axes called ax, and I want to set several of its properties. Currently, I do …

python matplotlib idioms
How do I cache a method with Ruby/Rails?

I have an expensive (time-consuming) external request to another web service I need to make, and I'd like to cache …

ruby-on-rails ruby caching idioms memoization
What are some GraphQL schema naming best practices?

I'm beginning development on a nontrivial application for which we're considering GraphQL. When working on the initial draft of our …

reactjs schema graphql idioms
Is there a downside to adding an anonymous empty delegate on event declaration?

I have seen a few mentions of this idiom (including on SO): // Deliberately empty subscriber public event EventHandler AskQuestion = delegate {}; …

c# coding-style delegates events idioms
Best practice for long string literals in Go

I've got a long string literal in Go: db.Exec("UPDATE mytable SET (I, Have, Lots, Of, Fields) = ('suchalongvalue', 'thisislongaswell', …

string go literals idioms
Rails idiom to avoid duplicates in has_many :through

I have a standard many-to-many relationship between users and roles in my Rails app: class User < ActiveRecord::Base has_…

ruby-on-rails activerecord associations idioms
What is the idiomatic way to assoc several keys/values in a nested map in Clojure?

Imagine you have a map like this: (def person { :name { :first-name "John" :middle-name "Michael" :last-name "Smith" }}) What is the idiomatic …

clojure idioms
Python indentation in "empty lines"

Which is preferred ("." indicating whitespace)? A) def foo(): x = 1 y = 2 .... if True: bar() B) def foo(): x = 1 y = 2 if True: …

python coding-style idioms
Is there a JavaScript idiom to change "undefined" to "null"?

There's quite a few JavaScript idioms that coerce between types and similar things. ! can convert anything falsey to boolean true, !! …

javascript null undefined idioms coercion