Is str.replace(..).replace(..) ad nauseam a standard idiom in Python?

Do you have an application that is running too slow and you profiled it to find that a line like this snippet is causing it to be slow? Bottlenecks occur at unexpected places. The current snippet traverses the string 5 times, doing one thing each time. You are suggesting traversing it once, probably doing doing … Read more

Pythonic way to have a choice of 2-3 options as an argument to a function

If the point Niklas’ makes in his answer doesn’t hold, I would use a string argument. There are Python modules in the standard library that use similar arguments. For example csv.reader(). sim_func(a, b, c, sim_type=”solar”) Remember to give a reasonable error inside the function, that helps people out if they type in the wrong thing. … Read more

Golang and inheritance

As mentioned in people’s comments, Go encourages composition over inheritance. To address your question about reducing code duplication, you would want to use embedding. Using the example from Effective Go linked above, you start with very narrow interfaces that only do a few things: type Reader interface { Read(p []byte) (n int, err error) } … Read more

Is there a JavaScript idiom to change “undefined” to “null”?

Javascript now supports a null-coalescing operator: ??. It may not be production-ready (consult the support table), but it’s certainly safe to use with Node or a transpiler (TypeScript, Babel, etc.). Per MDN, The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)