r/learnpython • u/fisfia • Nov 27 '20
Milestone - 1,000 lines of code - TU r/learnpython!
Hi friends,
Just wanted to tell you all that I reached my first 1,000 lines of Python code (wanted to show a pic, but not allowed). I'm going through the book Python Crash Course, 2nd edition and doing all the exercises and some of the examples. Strongly recommend this resource, as so many others already have done. Also, I want to say a huge thank you to this community! I wouldn't have come this far without you <3
4
u/queen-of-drama Nov 27 '20
To which chapter are you ? Almost to the end of chapter 3 (lists and all) for me. I started yesterday and having a lot of fun. That's an amazing book indeed.
3
u/fisfia Nov 27 '20 edited Nov 27 '20
I'm in chapter 7. I think I've "overdone" it a little though. Don't think others will hit 1,000 lines at this point since I also included some examples from the "plain" text. Work on friend, it keeps being really fun, promise :D
1
u/queen-of-drama Nov 27 '20
Coooool ! I’m having a blast anyway ! It’s like playing video games ahah
54
u/potato-sword Nov 27 '20
Congrats! Just a suggestion for the future, try not to measure your learning / success by lines of code written as there is no correlation between the two.
You may find yourself refactoring code to increase reusability which can reduce the number of lines. As well, you may be able to accomplish some tasks in just a couple lines depending on the implementation. For example, using a list comprehension instead of a for loop.
17
u/TheTruthIsOutThur Nov 27 '20
I'm not sure I'd say there's no correlation. Lines of code is a metric of time spent coding, and I definitely would say the more you practice the better you are. Even if these 1000 lines OP is mentioning are garbage, I bet OP is a lot more competent now than before they wrote them.
That said. "Time spent coding" is probably more correlated haha
5
u/soul_fly25 Nov 27 '20
I agree, I would not say there is no correlation and I 100% back the more practice the better. Coding is a skill that requires constant practice. But practice doesn't consist of purely writing code. Lines of code written is a shit metric of measurement as it doesn't account for any real world factors.
Things like complexity of the problem being solved, reading and understanding the existing code base you're going to add to or fix a bug in, design and architecture, hashing out stakeholder requirements etc.. all require significant practice. But if you're looking at how many lines of code did you write, you're ignoring the value that all these other things bring to the code you do write.
4
u/potato-sword Nov 27 '20
I agree, writing code is good, and you learn by coding.
But from my own experiences, I've found that during my learning journeys I would reach a point where I realized less is more. By this I mean, I started learning how to write more succinct code, whether it was with syntactic sugaring, reusable components, or implementing libraries. I would often look back at my past spaghetti code, and wonder why I spent hundreds of lines of code to implement something that could be done in less.
Overall, I think there are better ways to measure your learning. I believe creating a learning plan consisting of concrete and measurable goals for yourself can be one way to do this, but mileage may vary.
1
u/lolslim 🐍Telegram🤖 Nov 27 '20
honestly this is how I feel right now, I feel so accomplished on this python script, and since I coded other projects since, I went back and realized how WET I am, and trying to DRY it up now.
Hehe, word play.
2
u/ryrythe3rd Nov 27 '20
I get DRY, but what is WET?
2
3
u/lolslim 🐍Telegram🤖 Nov 27 '20
WET = "Write Everything Twice"
1
1
14
5
u/Nephty23 Nov 27 '20
That sounds awesome ! But a tip for the future as someone said : don't take the number of lines as a "checkpoint". If you try to make more lines to feel accomplished you might end up doing inefficient code. I am keeping track of all of my useful functions in one file with a description and all that stuff, it contains around 400 lines, for... less than 10 functions. Because around 60% of the lines are comments for the help() function and 20-30% are errors handling.
1
2
2
u/lolslim 🐍Telegram🤖 Nov 27 '20
Congrats OP,
Word of warning, you either get in the habit of spaces or tabs, and stick with it. Biggest project I have ever done was a telegram bot, I used spaces originally, but started to favor tabs, and went to tabs only, in 15 files, I still have a bunch of functions using spaces still since I never had to touch them to make changes.
Before I knew I can convert whitespace to tabs in atom IDE, I would use tabs inside a function that were all spaces, and got inconsistent spacing errors, it was a annoyance to say the least.
1
Nov 28 '20
easy fix, put this in your .vimrc:
set expandtab tabstop=4 shiftwidth=4Then, when your in the file you want too convert too spaces, just.
:retabAnd it will automatically replace every tab with 4 spaces.
2
2
u/E_Man91 Dec 14 '20
Very nice, congratulations to you!
I’m going through PCC as well and absolutely love this book. I’ve read through a lot of ATBS as well, but I like how PCC has half of the book dedicated to working on larger projects.
I’m currently on chapter 15 going through some basic plotting stuff. It’s hard to put this book down. Between the books, reddit, and watching some videos, I feel like I’ve learned a lot in just a couple of months.
Keep it up!
1
u/furrylouis Nov 27 '20
Thanks for the reminder! I have it, just have to start. I am currently working with Atbs
1
u/andrewneilclarke Nov 27 '20
Well done! Im also doing this book and just arrived at the Projects which is daunting but I'm going for it! Good luck with the rest!
1
Nov 28 '20
Great man! Keep it up! I started learning Python about 15 days ago, I have completed the basics and currently learning GUI. If any professional Python programmer/coder/developer is reading this can you please suggest me things to move forward fast (I currently have a lot of time so) I'd be glad to get any kind of help. Any plans, tips, strategies anything. Thank You!
1
u/rpr421 Nov 28 '20
I am reading the same book. I am on chapter inheritance, never thought how many codes I have written. Any guess ?
0
Nov 28 '20 edited Nov 28 '20
The less lines of code the better. Python is a bloated language anyway, don't make it worse with developer bloat.
0
Nov 27 '20
[deleted]
8
u/fisfia Nov 27 '20
Fortunately not :) No, I just added up all the exercises in one document to be able to search for stuff I already solved, and to see my progress. So to be clear (not a stupid question at all!): it's when putting all lines from every exercises in the entire book thus far in a single file of flow. This file will not really be runnable so to speak. It's just my "documentation". I do the challenges in separate files to be able to try if they work.
9
u/OriginalTyphus Nov 27 '20
Now make every exercise a function and let the user decide which excersice to run from the CLI :D
3
u/fisfia Nov 27 '20
Great suggestion, I think ;) Haven't reached the function chapter yet. Working on it. Will get back to you on that, I hope!
3
u/OriginalTyphus Nov 27 '20
Let me know if you need any help ;)
2
u/fisfia Nov 27 '20
Thanks :D I don't even know how much I'd need that yet, do I?
4
u/OriginalTyphus Nov 27 '20
Functions are friendly creatures that help you to tidy up your code. Once you get to know them, you will love them.
2
3
u/pedru_pablu Nov 27 '20
1000 lines of code and you havent seen the function chapter? how long have you been learning if i may ask ?
Im also learning and i think im not even at 500lines, but im already at Object oriented programing
7
u/fisfia Nov 27 '20
Explained above. For how long I've been learning - this is such a hard to understand and common "competition". Why? How would that be best measured? I'm not counting the hours. I don't think the hours or weeks are more relevant than the progress in a book. Oc fun to be a quick learner but everyone does not have the luxury of choosing what to do with their time. Just wanted to share how happy I was I had done more than ever before in coding.
3
u/OriginalTyphus Nov 27 '20
I'm proud of you, no matter how fast you learn.
Also heres the W3 Page about Python Functions, i personally think W3 explains stuff really well:
1
u/pedru_pablu Nov 28 '20
jajaja hey no chill, ive been learning for almost 3 months, OOP is pretty hard, thats why im impressed by the 1000 lines of code.
" Not things, but opinions about things, trouble men. " Epictetus
4
u/vectorpropio Nov 27 '20
Now you can make a python script that transverse a directory and print filenames and lines of code, and total line couture at the end.
Also learn to use other tools. If you are in Linux read about grep,wc and (bu this one is more trickier) find.
2
u/fisfia Nov 27 '20
Thanks for the great suggestions!! I'll continue my way through the book first then I'll get back to you when I reached the knowledge required to do what you suggest :D
3
u/vectorpropio Nov 27 '20
Oh, I didn't read that book, so i was off in my appreciation.
I'm not sure if the book touch pathlib. If not, after you will read about file and directories go everywhere to read how to use that library. It greatly simplify work with paths and blur the difference between windows and Linux
2
u/fisfia Nov 27 '20
Sounds cool! I'm looking forward to knowing all the things your talking about ;) Edit: And I'll look up pathlib. Used it yesterday, but just copy pasted hehe an example line into what I was doing. I'll check it out for reals!
1
2
Nov 27 '20
Instead of doing another course I strongly recommend starting on projects. I understand feeling like you didn't learn anything or don't know enough. I feel like that every day and have been programming professionally for a few years. Just break the project down into task and do one simple thing at a time. You for sure know how to print a welcome message, so start with that. Then move onto a menu, using argparse. If you don't know how to that it's ok just read the documentation. Move slowly from there. It's really the only way to cement knowledge. You won't do that doing canned exercise after canned exercise, I promise I wasted years trying to learn programming doing that. It wasn't until I just said F**k it and started doing projects that things actually clicked.
0
Nov 27 '20
[deleted]
0
u/scienceNotAuthority Nov 27 '20
Meh, only if there is good reason to.
OP doesn't sound like they need the code to be faster.
Although there's something beautiful about making your own classes and objects.... Still not sure if a noob needs to refactor.
I'd get onto my next project.
35
u/jdizzle4 Nov 27 '20
Every milestone counts, and every line you write will help you write the next. Congrats and keep going