What are some "Best Practices" you've applied recently?
A lot of what I've been doing is very obvious for most devs... But wasn't when I first wrote this particular code.
And a lot of it is stuff that's still tempting to ignore even with more experience, even when it's actively causing annoyance, but I'm always so much happier with code that's been cleaned up.
What are some of your favorite ways to refactor, polish, automate, and generally make code less hacky?
Stuff I've done lately, in no particular order:
* Get rid of stuff your dev tools don't understand. Don't just accept not being able to debug
* Heavy metaprogramming is generally in this category
* Logicless templates, or at least templates with less logic, keep code out of places the debugger can't follow
* Just use Pip, don't mess with sys.path and put dependencies in the repo where the linter doesn't understand them
* Don't do templating in languages the auto formatter doesn't understand
* Type annotations or static typing everywhere
* Schema validation: it doesn't just validate, you can also use the schema to generate UIs, use it to determine what keys to save from a larger superset, use it to fill in defaults, use it to strip defaults, etc.
* Schemas are also free documentation
* Use a Makefile or some similar tool, to gather up any scripts or snippets you will need, even if you're not doing C/C++. Don't just have a pile of scripts or a readme of snippets.
* Eliminate rarely used features that depend on obscure hand maintained middleware
* Don't go out of your way to add support for crappy hacky ways of doing things.
* Just say "Use a virtualenv, I will not make any effort to support not using one"
* Use standard common protocols and file formats
* Use VCSable text for small amounts of data where possible, not some crazy binary thing
* Use feature branches and general Git good practices
* Re evaluate your just kind of OK tools and see if there's something better that's come out
* If your UI looks bad, add whitespace.
* Don't act like you're building a new general purpose language. Add stuff for concrete use cases with complete workflows in mind, not vague "wouldn't it be cool if" ideas.
* Don't make 1000 lines of plugin APIs if it's only for one thing that could be a 10 line core feature.
4 comments
[ 5.3 ms ] story [ 17.7 ms ] threadeg. what is preferable for which kind of org and projects etc. I see this as a very org and project specific thing and whenever I have to suggest a flow to someone or decide one for myself, it's almost "what feels right+any reasoning around why the other flow might not be suited etc", but i don't always feel confident about it.
There was one place where I was the one to introduce VCS, and nobody wanted to learn branches. I didn't complain because I was just happy to have git at all and I was making more than I ever had before.
- The UNIX philosophy of simple, simple-purpose software that interoperates well.
- Privacy by default. It's a lot easier to navigate GDPR if you don't collect personal data.
- Write simple software with few dependencies. I'm tired of maintaining systems. I want technology to require as little attention as possible.