r/learnpython • u/RandomPantsAppear • Feb 13 '19
Some Lessons from 16+ Years of Development
Inspired by /u/ skiutoss 's post, I thought I'd add my own lessons.
Some other people probably got more from their years than I did - I started young(12-14) and I'm stubborn. But I somehow managed to bootstrap a 25+ person company, and have avoided working for anyone but myself and a few clients since I was 15. The only office I've really set foot in is the one I ran. Here are some things I've learned.
Most of this is related to SAAS services written in python.
Your best programs and projects will be solving problems that you yourself have. If you're lucky, other people will have that problem too. If you're really lucky, they'll pay for your solution.
- Your best libraries will be solving problems you have while programming. Write them, learn them, love them.
Your past work is your best resource.
- Because of how you code, you're likely to encounter similar issues. Standing examples of "how I did this" are tremendous resources.
- Especially if you're a contract worker, developing your own helper libraries that each contract explicitly gives you the rights to (I offer a transferable license to my prior work, and myself ownership) is worth it's weight in gold. It grows and grows and grows.
- Don't re-invent the wheel, but don't use a dumptruck to move a toothpick just because it exists.
Coding structure (classes, inheritance, etc) are not for your software as-is, it's for what it will become.
- You will always be hung from your largest monolithic function.
- When one function is made to do X and you already have a worse function to do X, the old function is to be deleted immediately.
- Misleading variable names are to be exterminated on sight.
Consistent variable names will save you huge amounts of time, reduce bugs, and save time for coders you onboard.
- Example: product_title in the function that determines the title, product_title in the dict it writes to a queue, product_title in the database, product_title in the json from the ajax call from the website, product_title as the javascript variable storing it on the site.
Every piece of code should be written with a thought to how hard it will be to replace some day.
- This is where well defined objects, microservices, and redis queues of tasks/objects shine.
If you can't code to scale(because time constraints), code to buy yourself time to do so in the future.
- As an example: If you are directly writing to a SQL database and it has the potential to be slow in the future, write the needed data to a redis queue and have workers execute it. When it starts to get hairy you can tick up the number of threads while you figure out how to speed up the DB or migrate to a new one.
- "Clever" code should be readable. If it's not, it's a detriment not a benefit. Coding is not your opportunity to show how much smarter you are than everyone else(who will have to maintain your shit)
- No, you won't remember. TODO lists and comments are vital.
- It is rare that you have a legitimate reason to be handwriting SQL queries.
- You will always need a dev environment. Develop scripts for setting them up.
- One of the greatest skills a programmer can have(especially one who works on early stage start-ups) is figuring out which corners can and can't be cut, and setting up the project to be easily fixed in the future.
The less billing code you are writing, the better.
- Significant issues in billing and backups are unforgivable tier errors. Clients and users will forgive downtime, they will not forgive their card being billed at random.
- There are companies who handle things like subscriptions. Use them. Do not write your own.
Don't just have backups, have an environment for testing those backups. Know how you're going to pause new incoming data when they're applied. Have a system that blows your phone the fuck up if they fail.
- In many cases, a failed backup is a company-ender. It's that serious.
- A master/slave configuration is not a backup. It will save you from hard drives roasting, not a sloppy "UPDATE" query.
- Come to terms with the mortality of your hardware.
- Do not trust user input. Not their cookie, not their form input, and never their uploads. Javascript validation is for telling the user their input is wrong, not for keeping your data clean. That is done server side.
80
u/Binary101010 Feb 13 '19
I don't remember the source of the quote that corroborates this, but it goes something like:
"You need to be five times cleverer to debug code than to write it. So if you write the cleverest code you can, you are by definition unqualified to debug it."
15
u/[deleted] Feb 13 '19
Can you kindly expand on this one? I am trying to enter the industry and don't have any experience (yet). Do folks just recycle previously written queries?
12
u/chzaplx Feb 14 '19
This is exactly what I think every time someone suggests using Pandas for some relatively simple problem. I mean sure, if you *know* Pandas well, it might take you less time to do it that way, but it's just going to be an even bigger time sink for a lot of novices to delve into that, when it's not at all necessary to solve their issue.
23
u/[deleted] Feb 13 '19 edited Feb 13 '19
I do not agree with this point, and would like to touch on it.
You shouldn't have SQL queries in your application to begin with. These should be wrapped in a Stored Procedure on the database side.
This provides:
Furthermore, ORMs tend to write sloppy queries and do not account for all the design decisions that a Data Architect/Designer would make. Ultimately, and especially in larger architecture environments - Data Architect's may need to make the decision on cutting their own wrists and maintaining 3NF or going off the beaten path to keep the architecture simple and performant. An ORM cannot possibly know these design decisions.
When possible, your SQL should live in your database, and it should be hand-written. Your database should have a well-designed, clean Data Abstraction Layer that does not get in the way of the Application Developer from writing their software and totally nullifies the need for an ORM or any other like tooling.
10
u/Vaguely_accurate Feb 13 '19
Also, follow the 3-2-1 rule for backups.
Have 3 copies of any data, on 2 different media, 1 off-site.
To modify that a bit, have at least one copy offline as well. I've seen instances reported where the same ransomware infection encrypted both the entire production environment and their Veeam backup servers, wiping al of their backups. In another example from this week VFEmail lost what looks like everything to what looks like a malicious actor with the right passwords. They just logged into the backup server and wiped the disk.
5
u/RaptorF22 Feb 14 '19
I'm curious how can I become you? I can code a bit of Python from my 2 years as DevOps but I am not by any means a "programmer" by trade.
Should I maybe go back to school?
4
u/-NewGuy Feb 14 '19
What is the language you use in your contracts to grant you the license to your helper libraries?
4
u/RR_2025 Feb 14 '19
Hey Op, that's really great and enlightening! Is this the post you were referring to?
107
u/otfjokes Feb 13 '19
Having to go and fix a bug on an old file... "Oh man, this code is trash! I don't understand any of this, who wrote this garbage!!! ....Ohh wait, I wrote this. Damn. What was I thinking!?!? And why are there no comments!?"
Great list! Thank you!
2
u/RaptorF22 Feb 14 '19
Or hire DevOps!
Source: Am DevOps.
9
u/solitarium Feb 13 '19
One of the many gems that will go a very long way
6
u/doczilla Feb 14 '19
Thanks OP, this is great stuff. Lessons like these learned over time are priceless to up-and-comers like myself.
5
u/[deleted] Feb 13 '19
Sooo...... the fact that I do this multiple times a day is a bad sign?
5
u/VicinalBun Feb 14 '19
Thanks for sharing wisdom with us , Sir
1
u/Biermoese Feb 14 '19
> The less billing code you are writing, the better.
What is billing code?
1
u/TheCrafft Feb 14 '19
If you use opensource libraries (numpy, scipy, pandas, OpenCV ect) within your coding are you allowed to get paid for the work as independent developer?
1
u/frankilla44 Feb 14 '19
could you expand a little on the "it's rare that you have a legitimate reason to be handwriting SQL queries"? should everything be passed as an argument always? For work i do there are a bunch of pieces i hard code and the rest I pass as args.
1
u/CSharpSauce Feb 15 '19
In my career, a bit over a decade in, the thing that has changed the least is SQL. There was a brief period in 2013 or something where everyone thought NoSQL would take over the world, but SQL remains alive and bigger than ever.
I would give the opposite advice to young folks. Learn SQL, get really good at it. Good SQL skills will take you further in your career than good ORM skills.
3
u/sharkbound Github sharkbound Feb 13 '19
i out this myself when working on a bot, i was adding a new command type, and it turned out to be a lot easier than i thought because of how it was structured with the inheritance.
It also taught me the importance of doing it right the first time as well
2
u/PurelyApplied Feb 14 '19
And my personal biggest pet peeve: your codebase is not your TODO list. During development, fine, but if you're committing your code, your TODOs need to become tickets for future work.
2
u/[deleted] Feb 14 '19
Thoughts from someone 1.3 years in. The look at every piece of code like are going to replace it someday resonated with me the most. Tbh took me a year to realize this is a good way to think.
2
u/sqqz Feb 14 '19
I don't have near the experience you have but I do recognize myself in a lot of your values working professionally as a software engineer. Very good points. Nice text
1
u/TotesMessenger Feb 14 '19
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
1
u/atcoyou Feb 14 '19
This this this. I always hear people talk about job security, but damn... you don' want to be managing the same thing your whole career. In my experience, once you can pawn things off on others (delegate is probably a better word...) you get to move to more interesting things in my experience... or at least new things and continue to grow.
1
u/ganjlord Feb 14 '19 edited Feb 14 '19
Also, keep it simple. You should build software that is made up of a hierarchy of components, each with a narrow, well-defined purpose.
-- Tony Hoare
1
u/linuxlib Feb 14 '19
This is the best piece of advice I have after many years of development experience. I would extend it by saying code is either "clever" or readable. I don't think I've ever seen a bit of code that was both. You're either getting the job done well or you're trying to show off. Show off code usually gets replaced by maintainable (readable) code.
Don't be the twit everyone laughs at when they leave because they thought they were clever.
From the wiki article on Python: "To describe something as 'clever' is not considered a compliment in the Python culture."
1
u/PrincessRTFM Feb 14 '19
My objection - my singular and sole objection - is that none of this is python-specific. In fact, it is mostly independent of language, platform, or environment. This advice is invaluable, but I had to find it from the /r/ProgrammerTIL crosspost because I'm not a python programmer - and yet, it applies to the languages I do use just as well.
1
u/fractalchemist Feb 14 '19
Love the tips! Thank you so much for sharing your experience.
1
u/spitfiredd Feb 14 '19
If you’re using vscode stop and install auto doc string, like right now. Or take the time to setup the one for your preferred ide/editor.
1
u/pasdavoine Feb 20 '19
> The less billing code you are writing, the better.
This hit us hard in my company, we shouldn't have done this (but maybe set up an ERP and talks to its API). This is really a lot of wasted time and effort.
0
u/[deleted] Feb 14 '19
[deleted] — view deleted comment
0
u/[deleted] Feb 13 '19
[deleted] — view deleted comment
0
u/[deleted] Feb 14 '19
[deleted] — view deleted comment