I had no idea what the phrase “idiomatic programming” meant and it wasn’t an easy find on the web. I thought I’d define idiomatic programming for any beginners out there.
Idiomatic programming means that your program contains statements that are unique to the language; i.e., you actually use the expressive power (or lack thereof – PHP) of the language in your programs.
Story time
When I started programming in college, I only knew C++. I used it for schoolwork and to build games. I (embarrassingly in hindsight) thought it was the only language worth knowing. Then I was forced to learn Java, coded in Visual Basic for a Summer gig, built an app and game with C#, and dabbled in some web languages like PHP. While it was great to learn new languages, I coded every single one like C++. This was not programming idiomatically.
This is a common mistake amongst programmers (across all skill levels really). Programming languages are all built on the core constructs (variables, branching, looping, functions, and objects) and it’s really easy to get used to expressing your thoughts the same way across languages.
The same holds true in spoken languages. I studied Polish for a semester and failed horribly to speak the language. I was good at vocabulary and catching on with the grammar, however, Polish is a very idiomatic language. I kept trying to use my English thoughts and translate them into Polish and it never worked.
That’s the beauty in functional programming languages like Lisp and Haskell. They force you to adopt their way of expressing thoughts. It’s hard at first; but not only is it a new challenge – the expressive power allows for a surprising level of succinctness in your programs.
In the search for programming idiomatically, learn the ins and outs of your current language; search for unique constructs.
It’s easy to settle on the first implementation, but for your own edification, revise your programs to be more idiomatic.
Happy coding!