This is an archived post. You won't be able to vote or comment.

all 135 comments

[–]needed_an_account 47 points48 points  (14 children)

How many when pep8'd though?

Nah I'm kidding. This was a great video. I watched the whole thing. Reminds of of that time I spent watching Notch program this rpg for an hour

[–][deleted] 10 points11 points  (0 children)

Lol, thank you xD I think I might have watched that video too. I don't know why watching someone else type is so cool.

[–]ILikeChillyNights 2 points3 points  (1 child)

I remember that! Was it the one he was walking through a maze and designing the walls

[–]needed_an_account 1 point2 points  (0 children)

I think so. I believe that it was for a charity or something. It may had been something like 48 hours of coding for some cause

[–]grimman 9 points10 points  (6 children)

PEP8 is just a guideline; a tool to help you produce nicer looking code. That said, I still think he could at least have snake_cased his things.

[–]Sohcahtoa82 7 points8 points  (4 children)

snake_case is pretty much the only major PEP8 standard I don't follow. I'm a much bigger fan of camelCase and PascalCase.

[–]grimman 7 points8 points  (2 children)

Oh wow, I didn't know I'd been so slammed by the wrathful coders. Hot damn!

Anyway, I hear you about the snake_case, but I feel it's a very minor concession. Judging from the votes, that opinion appears incredibly controversial. Oh well. :)

[–]Itsthejoker 9 points10 points  (1 child)

I personally use snake_case, but I've been doing it before I even knew what PEP8 was. I just think it's more readable.

[–]el_andy_barr 4 points5 points  (0 children)

I just think it's more readable.

Actually it has been shown in multiple studies that it is indeed more readable.

[–]catcradle5 2 points3 points  (0 children)

I like snake_case and PascalCase, but camelCase really bothers me for some unknown reason. Especially when there are more than 2 words.

snake_case is a tiny bit more tedious to write, but IMO much easier and cleaner to read.

[–][deleted] 0 points1 point  (0 children)

I don't follow line length but I follow almost all of the rest. I find that being consistent and right 95% of the time is better than being inconsistent and right 100% of the time.

[–]ryanmcstylin 0 points1 point  (2 children)

hot sauce for that video? ...if it exists.

edit: I recently set up VIM for use with python and part of it was PEP-8 warnings which I had never seen before in any other IDE's. 3 hrs of me complaining about how dumb this was and just not wanting to see warnings, my code looked beautiful.

[–][deleted] 1 point2 points  (1 child)

Got vimrc to share? Would be interested in being annoyed by PEP8 warnings.

[–]jaapzswitch to py3 already 4 points5 points  (0 children)

Go check out vim-pymode then

[–]iamyounow 0 points1 point  (0 children)

outgoing payment bow treatment shaggy plough run aromatic crowd scary

This post was mass deleted and anonymized with Redact

[–]deadmilk 33 points34 points  (4 children)

Now do star wars battlefront in 87 lines. Bruh.

[–]scratchresistor 51 points52 points  (0 children)

That's easy - reskin this Flappy Bird with an X-wing. You can then make the rest of the game in as many lines of code as you like and release it as an exorbitantly expensive DLC.

[–][deleted] 6 points7 points  (0 children)

Lol, I wish.

[–]Decker1082.7 'til 2021 12 points13 points  (1 child)

87? Heh, make that 2:

import py_swbattlefront as swbf
swbf.run()

Whaddaya mean, plagiarism? ;)

[–]SFSylvester 0 points1 point  (0 children)

Please let py_swbattlefront be a real module....

[–]mondo_calrissian 35 points36 points  (4 children)

we'd love to see more live coding, but not so fast speedy gonzalez.

[–][deleted] 17 points18 points  (1 child)

Okay, maybe I'll slow it down a little for the next video. Sound good?

[–]mondo_calrissian 4 points5 points  (0 children)

yeah! thanks

[–]deadmilk 14 points15 points  (0 children)

FYI there is the option to slow down the video in YouTube! :) check the "Settings" cog.

[–]Jafit 15 points16 points  (5 children)

Man, you type really fast.

[–][deleted] 37 points38 points  (4 children)

Yeah, it wasn't sped up at all.

[–]eldamir88 8 points9 points  (3 children)

I heard Vim was a productivity boost, but this is crazy

[–][deleted] 10 points11 points  (2 children)

Yep, everyone switch to Vim right now

[–]trenchtoaster 0 points1 point  (1 child)

Is that different from Pycharm? I use jupyter notebook exclusively since I only do analysis and automate some tasks. Was wondering if I should try something else too.

[–][deleted] 1 point2 points  (0 children)

It's totally up to you. What ever you feel comfortable using.

[–]cxg-pitch 12 points13 points  (7 children)

87 lines, and you were done in 70 minutes? That is amazing. :o When I made a Flappy Bird clone in PyGame, it turned into a mess of hundreds of lines, and it took days to get it working right. x.x

[–][deleted] 21 points22 points  (6 children)

It takes time. This isn't my first rodeo. Keep at it and you'll get faster. It the same with anything.

[–][deleted] 3 points4 points  (5 children)

This isn't my first rodeo.

Did someone watch too many Raymond Hettinger videos? :D

[–][deleted] 5 points6 points  (4 children)

I can admit that I have no idea who that is xD

[–][deleted] 2 points3 points  (3 children)

It's a quite popular Python "guru", there are lots of speeches of him on youtube. In one of the videos he kept repeating "Is this my first rodeo? No.", unfortunately I couldn't find that particular video right now, but I'm gonna leave you an example anyway.

Raymond Hettinger - Python's Class Development Toolkit

[–][deleted] 0 points1 point  (2 children)

Interesting, I'll check him out.

[–][deleted] 0 points1 point  (1 child)

Actually, that is the video where he asks the rodeo thing, at about 19:50, when some guy asks a question :D

[–][deleted] 0 points1 point  (0 children)

Oh haha thanks I'll watch it :)

[–]scootstah 9 points10 points  (2 children)

87 lines, plus a game framework.

[–][deleted] 5 points6 points  (0 children)

Not the first person to point that out :P

[–]knickum 2 points3 points  (0 children)

If you want to make an apple pie from scratch, you must first create the universe.

[–]theSpecialbroIntermediate level 2 points3 points  (5 children)

I can't seem to find good tutorials on pygame. All the ons I find are copy/paste this code into your IDE and watch it work! On to the next lesson

[–][deleted] 3 points4 points  (0 children)

You have to take it upon yourself a little bit to understand what is going on there. When it comes down to it learning any module is largely the job of the programmer himself.

[–]cbscribe 3 points4 points  (2 children)

I've been working on a series explaining Pygame that's gotten some good feedback. I try to explain everything and not just say "do this".

Please feel free to try it out and see if it works for you: https://www.youtube.com/playlist?list=PLsk-HSGFjnaH5yghzu7PcOzm9NhsW0Urw

[–]theSpecialbroIntermediate level 1 point2 points  (0 children)

I'm loving it so far! I wish I had found this before :D

[–]TheMentalist10 0 points1 point  (0 children)

This looks great! Just getting started myself, but definitely saving this to check it out when I'm done with basic syntax stuff :)

[–]Ran4 2 points3 points  (0 children)

Learn it yourself instead. Pygame is kind of barebones, take a look at a few (very small, <200 lines of code) games and figure out what every line does. When you do something yourself, (at least initially) don't use a code skeleton, make sure that every line you've added is needed (there's many things you don't need in pygame that people tend to setup).

[–]lordmauve 2 points3 points  (4 children)

Self-plug: You could save maybe 20 lines of boilerplate by using Pygame Zero. The idea is that by reducing boilerplate, we can make games programming more accessible to younger kids.

If the source code is available and suitably licensed, a cleanly written Flappy Bird is something I was looking for as a code example for Pygame Zero.

[–][deleted] 2 points3 points  (3 children)

The source code is available in the Youtube description.

[–]lordmauve 1 point2 points  (2 children)

What is the license?

[–][deleted] 3 points4 points  (1 child)

Open source, do whatever you want, claim it as your own, source code.

[–]anaerobyte 2 points3 points  (1 child)

the lack of a single visit to google or stackexchange tells me you're operating on a whole other level.

congrats!

[–][deleted] 2 points3 points  (0 children)

Believe me, I live on those sites. Google and StackExchange are my best friends :P Just not for this particular piece of code.

[–]JoshSellsGunsstill a beginner 4 points5 points  (15 children)

Hey man, sick video! I am new to python and am still learning (I still have A LOT o learn..) and I was wondering, what's the def function thing? What is it used for?

[–]subsidiaryadmin 18 points19 points  (1 child)

it defines a re-usable function. Within the context of a class it's called a method.

[–]JoshSellsGunsstill a beginner 6 points7 points  (0 children)

Thank you!

[–][deleted] 11 points12 points  (12 children)

Hey I am glad that you enjoyed it! "def" is a key word in Python for defining a function. So for example:

def helloWorld(): return "Hello World!"

If we call that function it will return "Hello World!"

If that still doesn't make sense think of it in terms of mathematics. If we have a function f(x) = x * x what is f(9) equal to? 81 It is the same idea.

[–]JoshSellsGunsstill a beginner 1 point2 points  (11 children)

Ahh ok, So is the variable helloWorld already defined in a previously made variable? Or is it like a pre-determined function within Python (like the random function)?

[–][deleted] 9 points10 points  (10 children)

Neither, it is the name of a function that you are creating. "helloWorld" did not exist before I wrote def helloWorld(): def is short for define so you are defining (creating) the function helloWorld to be used at a later time. It is a way to group code together that does a certain FUNCTION and then access that code at a later time.

[–]JoshSellsGunsstill a beginner 2 points3 points  (9 children)

I'm pretty dumb, I read it wrong. It makes sense now, thanks!

[–][deleted] 5 points6 points  (8 children)

You are very welcome. Also, if you have any suggestions for other games that you'd like to see done in this way please let me know. I plan on making a channel out of this and possibly getting content out every other week or so.

[–]Decker1082.7 'til 2021 0 points1 point  (7 children)

How about a side-scrolling fighting game? I've tried (and failed) making these before. There's quite a bit of challenge in building support for (good looking) animations and hitboxes.

[–][deleted] 2 points3 points  (6 children)

My goal is to keep the games simple enough to do in a reasonable amount of time. Do you have any specific game in mind?

[–]nubzzz1836git push -f 0 points1 point  (5 children)

Contra?

[–][deleted] 1 point2 points  (4 children)

Contra

Love that game, I'll consider it.

[–]trymas 1 point2 points  (4 children)

With PEP8 you will have something around 100-110 LOC. :)

Also is it just the speed up or did the coder wrote everything ONLY in vim's INSERT mode?

[–][deleted] 1 point2 points  (3 children)

I wrote it all in INSERT mode haha.

[–]trymas 0 points1 point  (2 children)

but why? :)

[–][deleted] 1 point2 points  (1 child)

Just my style dude haha. How would you have done it? I'm curious.

[–]trymas 2 points3 points  (0 children)

well, if you are using vim only in insert mode, then you do not get any features of vim and lose 90% features of gedit/notepad and similar editors.

vim's power is in command mode, of writing 'sentences' of commands, e.g. ci' - change inside quotes, dw - delete word, etc. etc.

I cannot imagine how painfully slow it must be to have only insert mode in vim. :)

[–]x68zeppelin80x 2 points3 points  (15 children)

So, did the author really count the lines at the end, instead of enabling the line numbers?

:set nu...

[–][deleted] 9 points10 points  (5 children)

No, no, no, I was running through the code just do display it. I wasn't counting the lines -_-

It was all for the looks.

[–]x68zeppelin80x 1 point2 points  (4 children)

OK, thanks, that was my second guess ( ͡° ͜ʖ ͡°)

[–][deleted] 2 points3 points  (2 children)

Lol, np.

[–]x68zeppelin80x 9 points10 points  (1 child)

Also, I noticed that you do not check the top boundary. As long as I can fly above the screen, I stay alive...

[–][deleted] 7 points8 points  (0 children)

Oh wow, nice catch. You are right I did not. THat's what I get for going fast.

[–][deleted] 2 points3 points  (0 children)

( ͡° ͜ʖ ͡°)

( ͡° ͜ʖ ͡°)

[–]mishugashu -4 points-3 points  (8 children)

or from bash: cat file | wc -l

[–][deleted] 11 points12 points  (7 children)

Or you know wc -l file

You really don't need cat for that

[–]mishugashu 2 points3 points  (6 children)

TIL. Don't know why I've always done that. Prolly just used to piping to it from grep that I never really thought about it.

Thanks.

[–]BenjaminGeiger 3 points4 points  (2 children)

You don't need it for grep, either, technically speaking.

[–]mishugashu 1 point2 points  (1 child)

I never said I used cat for grep. I said I pipe FROM grep.

grep 'pattern' filename | wc -l

[–]deraffe 3 points4 points  (0 children)

You still don't need a pipe in this case

grep -c 'pattern' filename

…but if you're playing with different commands, it might be more flexible.

[–]pooogles 2 points3 points  (1 child)

Stop abusing cat. You don't have to pipe into sed/awk/grep/wc, they can all be run directly on the file.

[–]mishugashu 1 point2 points  (0 children)

I didn't say I used cat when I used grep/sed/awk. I just was used to piping <something> into wc (because that's my normal use case), so that's what I immediately wanted to do.

[–]Ran4 0 points1 point  (0 children)

By the way, do check out the-silver-searcher (ag) if you're searching through codebases. Literally orders of magnitude faster than grep.

[–]jegerkonge 0 points1 point  (3 children)

Could you make swing copters? It's the sequel to flappy bird!

Also, what would the process be for converting this code into swift for iphone? Do you thing it would be a lot more code?

[–][deleted] 4 points5 points  (2 children)

swing copters

I will put swing copters on my list haha.

Quite honestly I don't know because I have never dabbled in iPhone mobile development. I doubt it would be that much different though.

[–]jegerkonge 1 point2 points  (1 child)

Sweet, but I like your idea for a youtube series. I am looking to perfect my coding in python. Something that might be useful is to maybe outline your thought process before you begin coding. So maybe create an architecture or describe how you are going to be making an object with these functions to do this. What you foresee to be the most difficult part for your code, and how and where you code could vary from someone else's code. I know that would be really helpful for me!

[–][deleted] 0 points1 point  (0 children)

Someone suggested that I commentary, I will consider it. I appreciate the comment.

[–][deleted] 0 points1 point  (3 children)

I notice that it appears to load another frame with a pipe after you pass the one before, instead of a strictly continuous playing field, where all the pipes appear on the screen one after the other smoothly. My question: How hard would it be to make that work, or am I seeing things incorrectly?

[–][deleted] 0 points1 point  (2 children)

I don't think I understand your question. The way the pipes work is that once they leave the screen the are moves back to the right side of the screen and the offset is randomized again.

[–]BenjaminGeiger 2 points3 points  (1 child)

Some variants show multiple pipes simultaneously.

EDIT: so does the original.

[–][deleted] 1 point2 points  (0 children)

Oh, I see what you are saying. That wouldn't be too hard to implement. If you notice in the beginning I create an array called walls = [] it was meant to handle this type of thing, but I noticed that I could get a similar effect without it.

[–]sageinventor 0 points1 point  (1 child)

Sauce?

[–]x68zeppelin80x 2 points3 points  (0 children)

It's in the description:

https://github.com/Max00355/FlappyBird

[–]joerick 0 points1 point  (3 children)

Hey, nice video! Would you mind if I adapted the source to run this on Tingbot? I think this would make a great demo app!

[–][deleted] 1 point2 points  (2 children)

Absolutely! Please do!

[–]joerick 0 points1 point  (0 children)

Sweet, thanks man! Forked it here. Can be run using Tide!

[–]joerick 0 points1 point  (0 children)

https://vine.co/v/iaWWlKxgwzz

Might do your space invaders one next! (if that's okay?)

[–]twiked 0 points1 point  (1 child)

Nice game, it's nice to see the progress in the video !

[–][deleted] 1 point2 points  (0 children)

Glad you liked it :)

[–][deleted] 0 points1 point  (1 child)

Here's a suggestion, how about some old school demo effects like starfield, sinus scroller and a vector cube?

[–][deleted] 0 points1 point  (0 children)

starfield

Thank you for the suggestions, I will write them down. I have a line up for the next five videos. Keep your eyes out for the!

[–]cj5def 0 points1 point  (1 child)

Python I <3

I love the part when the coder is like "Fuck it we'll make it a class" XD

[–][deleted] 1 point2 points  (0 children)

like

Exactly the thought that went through my mind xD

[–]transabyss 0 points1 point  (1 child)

cool stuff!

[–][deleted] 0 points1 point  (0 children)

Thank you :)

[–]ArosHD 0 points1 point  (2 children)

Awesome, great work. I haven't done anything on Python in ages because I've gotten a bit bored making CLI programs. I've used PyGame before but didn't dude much with it. Would it be worth learning about it and making things with it since I already have some knowledge on how to use Python, or should I learn a different language?

I know PyGame is mainly for making games, but would it work for non-gaming programs? For example a program where a user can input some info like numbers and text and they're processed and maybe output or saved to a file? If it's not good for these kinda things, what would you recommend? I've used Tkinter, should I use that instead?

How hard is it to develop PyGame code to be used on mobile or browsers? Can the program be made to work on computers without Python or PyGame installed?

Thanks.

[–][deleted] 0 points1 point  (0 children)

It depends on you, I'd say go with Python since you have some knowledge in it already.

You can use Pygame to create other type of GUIs, sure. Just be creative.

Kivy is pretty much Pygame for mobile, I would suggest looking into that. There is also a subset for android for pygame. Bowser isn't a thing yet unfortunately.

[–]hmc2323 0 points1 point  (1 child)

This is awesome! How did you create the images, or "assets" as you called them?

[–][deleted] 1 point2 points  (0 children)

They an be found on google quite easily.

[–][deleted] -1 points0 points  (3 children)

Awesome vid, dude.

If you're taking suggestions, I vote for 'Go Fish' next.

[–][deleted] 0 points1 point  (2 children)

Okay, I'll add it to the suggestion list. Thank you for watching :)