2 ms·
It's not as difficult as people tend to imagine. Most of the time people fall into the trap of thinking that experts in any given field are experts because they
by InclinedPlane 10y ago
It's not as difficult as people tend to imagine. Most of the time people fall into the trap of thinking that experts in any given field are experts because they know some secret way of doing things that is difficult to learn. The reality is that most experts (whether it's in rock climbing, bread baking, or coding) have a superior mastery of the fundamentals. In code the best thing to concentrate on is writing clear code that works correctly. The clearer the code the easier it is to figure out whether or not it works as it's supposed to, which is win/win.
In general I'd recommend every developer read the book "Refactoring", because the lessons in there are so fundamentally important to development everyone should have them in front of mind as often as possible. Learning about "code smells" and how to transform code from one way of working to another cleanly is hugely important, and that's the "bread and butter" of what good coding is like day to day. Specifically I'd say learn to use extract method and use it incessantly. Don't worry about creating small methods that only get called once (the compiler will optimize for you). Don't worry about creating "too many methods". Don't fret about having "meaty methods" that do "meaningful work" instead of just "trivial stuff", break down your code into components that have semantic meaning, even if they are small components. And if you end up with too many methods it likely means you're mixing up functionality for different things in one spot and need to split it out or you have a more fundamental design problem that needs to be addressed through simplification.
Overall, strive to make code readable and understandable. Learn the magic of well named variables and methods and pretty soon your code will start reading like an open book. Above all else, remember to be kind to your future self and others who might come along your code in the future. It's always tempting to leave a mess because it's "just temporary" or "you'll get back to fix it up later" but try to develop some basic levels of code sanitation so that you're not dumping garbage in the codebase all the time.