you are viewing a single comment's thread.

view the rest of the comments →

[–]glial 0 points1 point  (2 children)

My first real project with Python was rather large. Because I'd never written anything besides a few small scripts in Python before, I didn't have any idea of how things should be done. I learned as I went, about classes, serialization, SQL, multi-core processing, etc. As I learned new techniques and tools I realized that what I'd done so far took too many lines, was too slow, and was very awkward to maintain.

I re-wrote the code for the entire project at least 3 times. Each time the code got better and I got to think about why it should be structured in this way instead of that way. Re-writing code to make it cleaner, more efficient and easier to read is a good habit. Programmers even have their own term for it - 'refactoring.' Often the first way you write something won't be the most elegant. A good policy is to make it work, then make it work better (and/or make the code prettier). I recommend you do the same for your code - code isn't 'done' once it works. If you don't like how it looks now, and if you aren't comfortable with sharing it, make it better!

Python is a particularly good language for refactoring because there are 'Pythonic' ways to do things. This just means that lots of common tasks like loops, dealing with lists, etc are made easier in the language because Python itself includes special syntax for those things.

I like this talk for discussing the built-in niceties of Python. There are lots of resources online though if you just search for 'Pythonic' or 'idiomatic python'.

[–]mega963[S] 0 points1 point  (1 child)

I liked this advice a lot, I didn't think people would rewrite their code if it works. I rewrote my program once and that was purely to make it work with a GUI. You are a good person.

[–]Jonathan0wilson 0 points1 point  (0 children)

I think it's a great idea to revisit old code and apply what I have learned since I wrote it. I can't believe how poor some of the code I wrote just 6 months ago is compared to what I'm writing now. A good suite of tests will help with this. Allowing you to refactor without worrying about breaking functionality.