3 ms·
How to learn to program idiomatically?
What are the best ways/ resources for learning to program idiomatically? Almost every tutorial I've ever seen covers all aspects of a language's syntax equally, and doesn't talk about what's most important or what the best or most idiomatic ways are of doing things in that language (Case in point: I went into my first ever job w years ago with a comprehensive knowledge of Java, but didn't realize that these crazy things called "HashMaps" were actually important until my interview brought them up)
I'm currently learning Go, and understand most of the syntax and everything, but I fear if I just start blindly writing my own applications in it, I will take on a pythonic approach, since that is my current best language. How do I avoid this?
- mattbillenstein 12y agoRead the Golang source - I'd guess the best guys to learn writing go from are the guys who are making it.
- chrisshroba 12y agoHow would you recommend going about doing this? I just went to the Golang source and I'm a little overwhelmed by all there is. Do you think I should read all of it? Are there certain parts I should focus on? Any pointers would be really appreciated! Thanks!
- percept 12y agoYou could try examining the parts of the standard library used in your own (test) apps, and how they relate, to get a top-to-bottom view. Or start with smaller/less interdependent packages, if the larger ones seem too complicated at the beginning (just browse until you find ones that seem grokkable). Maybe look at stuff like input/output param patterns, naming (terse!), composition, etc. Ha, "pointers": https://groups.google.com/d/topic/golang-nuts/H7LrVJhXyv4/discussion https://groups.google.com/d/topic/golang-nuts/H7LrVJhXyv4/di... https://groups.google.com/d/topic/golang-nuts/x-huAZm8yP0/discussion https://groups.google.com/d/topic/golang-nuts/x-huAZm8yP0/di... https://groups.google.com/d/topic/golang-nuts/EfLHIHFNsjA/discussion https://groups.google.com/d/topic/golang-nuts/EfLHIHFNsjA/di...
- douche 12y agoFind some high-quality projects using the language, and study the source. Languages that have their standard libraries written in the language can be good for this. In a lot of languages, there are several different ways to skin a cat, and it can be confusing, particularly when what is considered idiomatic evolves over time as the language matures or different fashions come into prominence. I'm not sure you can really get a good grasp of what good, idiomatic code looks like without reading a lot of it; similar to the way I've always heard it said that the best way to become a good writer is to read a lot of good writing. After a while, you start to internalize it. I do love using JetBrains tools and editors, since they generally have pretty good linting and stylistic rules engines built in. Mostly, I work in C#, and ReSharper has improved the quality of the code I write immeasurably. At the very least, it helps evolve you towards a consistent style, but it can also suggest more idiomatic usages in some cases.
- coding4all 12y agoRead the source of your target language, mature projects, and find some style guides. There's going to be some contradictions in style, but you'll figure out what works best sooner than you might think.
- _RPM 12y agoI faced this same problem a few years ago when I started learning C. The best way I solved it was to take your favorite project in X language, and dive in. To find out where to start looking in the source, use tools like grep, or CTL-F to find a particular error message or some distinct message that your language yields.