ninecoffees

thank you cohost. take care.

  • she/her

Extremely useful 🇹🇼 Asian ⚧️ lesbian🏳️‍🌈
/ /
priv acc @finecoffees (mutuals only! this is where i'm authentic and real with my thoughts, also horny posting)
\ \
Writer, VIVIAN VIOLET, THE GOOD WEAPON
/ /
currently learning to code (HELP PLS)
\ \
I occasionally post about coffees and baking
/ /
massive proponent of walkable cities, public transport infrastructure, and undoing the destruction of Henry Fucking Ford
\ \
Always open to asks!


I had a 4 hour long chat with a friend yesterday catching up on life stuff:eggbug-uwu: and everything else, and we ended up talking about gamedev. He asked me, "why didn't you just implement X into your game since you wanted it so much?"

I told him--in no uncertain terms--that I didn't understand programming. It didn't make sense to me, no matter how many hours I meticulously poured over the documentation because nothing was explained.

"Okay, but did you learn the language?"

Wait, they expected me to learn the language before starting? I'm stupid???

I could hear the exasperation on the other end of the discord call. "Oh my fucking god, you've been CHINESE ROOM-ING programming! Of course you hate programming! This is why everyone at my workplace hates it! You're just copy and pasting stuff and changing variables until it works!"

That's not how amateurs like me do it??? I'm stupid???

"Go fucking learn programming!"

Yeah, but uni courses are expensive--

"You fucking idiot! Just learn it yourself online!"

YOU CAN DO THAT??? I'M STUPID???

OH MY GOD.

I'M STUPID.

personal study notes exam style for learning python
Document updated with arrays


You must log in to comment.

in reply to @ninecoffees's post:

Cool! So a function can have a bunch of arguments (as you noted above), which is what goes into it. It can also have a return value, which is what comes out of it when it's done. There can only ever be one return value for the function.

'Calling' a function just means you're running it. In this scenario, the 'caller' is the function that you're running it from. If I'm running function A, and A wants to run B, then A is the caller of B.

The return statement is used to tell the function what to send back as a result (and when). If I write a line that says

return x

that tells the function "stop everything you're doing, finish running on the current line, and give back the current value of x to the caller".

The caller then needs to put this value somewhere. In most languages, you do this the same way you'd assign a variable: with the equals sign. So if I write:

y = doSomething(z)

that means "call the doSomething function with argument z, and then whatever it returns, store that return value in y"

The thing is: you don't always want (or need) to return something when you call a function. Sometimes you just want it to end. So when you use the return statement, you can just write it as 'return', without any variables next to it, and it'll just end without sending anything back.

Big Nerd Caveats You Probably Don't Need To Worry About:

  • Only ever being able to return one thing at a time can seem like a big limitation. Partially it's a matter of language philosophy, but there's usually some ways around it. Depending on the language you might be able to return arrays, or objects, which can have multiple things inside them. But for now, try to just obey the limitation.
  • You might also see the terms 'jump in' and 'jump out' as alternative ways to describe entering and exiting a function. It's not necessary, but it may help to think of program execution this way. When you call a function, the program jumps into it, and when the function returns, the program jumps out. Wherever it was before it jumped in, it'll continue from that spot.
  • Functions can also have side effects, meaning that they change a variable that isn't going in or coming out. An example would be the function in your notes above:

CountMuppet.append(8)

This function doesn't return anything, and yet calling it clearly has changed the contents of the list. Therefore it has a side effect. You'll learn to write functions that can perform side effects eventually, but for now, it helps to think of a function as a sealed box, with arguments that come in, and a return value that comes out.

I don't think this is being stupid -- idk about you but this is something that was never presented to me. The idea that programming boils down to "you can actually learn a language and its grammar" as a starting point.
Like I genuinely think I never thought of it that way until someone tutored me about it and tried making a comparison to me 🤔

You've probably figured some of this out since then (I see other people in comments writing examples) but hopefully any of this helps in some way:

  • Arrays/lists: Usually in python (I assume this is python!) we stick to lists (like x = [a, b, c]) and tuples (like x = (a, b, c)). Lists are handy because you can add to them but they can be slow to check if they're big. Tuples are handy because they're fast to run through (like with a for loop, for instance!) but you can't change them. 90% of the time, if you have no idea, lists are fine, but if performance starts to be a thing, that's when tuples matter. (There's other kinds of organizations of data too - if you haven't sorted out what a dictionary is yet, that's a very good idea for python in particular.)
  • Functions are basically just cordoned off segments of code that you can call repeatedly to "replay" that code - this is better than copy/paste because if you ever have to change it, you're not changing it in several places. It also lets you declare various temporary variables without having to worry about them later because they're segmented off in that function.
    • Returns in functions are like...if the goal of a function is to output a specific thing, return is used for the thing it's outputting. You're probably using functions that effectively have returns already! For example, len(my_list) gets the length (number of things in) a list - if you were to rewrite that from scratch, you'd have it return an integer that represented how many things were in that list. A function like this is kind of like a factory that takes in a raw material and outputs a processed thing, but in this case it often won't change the raw material, because it's more useful to have both.
      • A return also kicks things back to right after the point where you started calling that function whenever it executes - so if there's code after a return in a function, it doesn't happen. (This is that "exit" bit they mentioned.) This works great with if statements.

Writing an example of something that uses a return in both ways:

def multiply_by_three_if_positive(input_number):
    if(input_number <= 0):
        return input_number

    output_number = input_number * 3
    return output_number

If input_number is less than or equal to 0, the return under that if statement happens and stops the rest of the function from happening, saving the computer some time. Otherwise, it continues onward to multiply that input by three and return it. So if you call that function like

x = multiply_by_three_if_positive(y)

you'll either get the y if it's negative/zero or 3*y if it's positive.

Hope any of this helps! Good luck going forward!

Btw, I don't know if you already figured out what call and return means, but I'll explain in my onw words:
Once you created a function, "calling" a function basically means executing it in your code. Return is an optional step you can add to your function that will end it and "give something back to you".
For example, let's say I have the function:
def sumTwoNumbers(num1, num2): return num1 + num2
what this function does is get two numbers as arguments, then return it's sum. And since it's returning the sum, we can "grab" the result when we are calling the function.
For example:
print(sumTwoNumbers(1, 2))
Will print "3" on the console because the function is returning a value to the "print()" function.
We can also declare variables with this method, for example:
number = sumTwoNumbers(5, 4)
now number == 9, because the function is returning a value to the variable declaration.

Anyway, I hope it helps somehow and goodluck with your studies :eggbug:

Saw this via the gamedev tag, thought I'd offer stranger advice which you can feel free to entirely ignore.

I taught myself to make games, starting when I was 11ish. It's been about 23 years since then, I think? What you wrote here sounds incredibly normal and like you're absolutely on the right path, even the stuff you say is a mistake.
-We all start by copying/pasting/changing variables and frankly that's one of the best ways to learn. Sure, you need to move on from there, so sounds like what you're doing now is the next step! Learning the grammar of programming is SUPER helpful for generating your own stuff from scratch. Your step 1 was absolutely necessary, though.
-No one knows what they're doing. At all times. Experience doesn't change that, but it will change your tolerance for sticking with it long enough to actually finish things you're proud of.
-The real trick is to just keep doing it. Find small wins you're happy with and don't criticize yourself for being new.
-Love your notes, by the way.

oh hey, I'm currently using the textbook, Python for Everybody by Charles R Severence, Microsoft VSC, along with an online answer sheet I found on github. This seems to be working fine except for the fact that 1) there's a slight inconsistency in the version of the textbook and 2) it seems everyone expects me to take COMPSCI 101. If I'm mildly confused about a topic, it seems to be slightly relevant to that regard, though how much I cannot tell as I've never touched an engineering subject in my life.
I originally started out with the website, Learnpython.org, but it assumed so much basic knowledge and presented the ideas in such a matter-of-fact way that it felt like I was chinese room-ing once more.

so this is going to be a big wall of text and it's just the tip of the adviceberg, but:

The books may expect you to know basic CS concepts, but imo that's a good thing. Treat it as a sort of puzzle, or like you're trying to track down a piece of information for something you care about, but is kinda niche.

Write down what you don't understand when you encounter it.
Skim the rest of the section noting down other parts you don't understand yet.

then Google search those questions, read the answers, write down what you don't understand, read the chapter again, repeat. Don't worry, you're smart enough, and if you don't understand something it just means you need to figure out how to break it apart into problems you can solve (even if that just means "figure out what name I need to Google to learn more" is the smaller piece )

after awhile you can move to doing chapters this way, then books.

which book doesn't really matter.

the dirty secret is that this field, and everything else, but especially this field of computing, boils down to 3 things: learning, problem solving, and then communicating those solutions to a computer or someone else, along with the how and why.


your notes pictured above look like you're focusing a lot on specific details of the internals of the language. but in my opinion and experience, if you learn more of the language, and start reading and writing more of it, those will come naturally and if not, be easy to practice.

knowing a list exists is important, knowing how to write one less so, at least at the beginning. Think about and note concepts and uses, if you don't memorize it automatically through use, it'll be easier later.

otherwise you can google "list in python" "what are the numbers inside the list called" "list slices python" "how to read a file python" etc. or use something like learnXinYminutes.com to find that language element and what it's called and then search those.

try not to let the small stuff like that slow you down at first. it's learned better through use.


the thing about functions and returns is that there's a few ways to think of them.

functions are keywords that when called, take whatever's optionally within the parentheses, (called "parameters" in function definitions, and "arguments" when being called, but people will understand if you use them interchangeably), they take the values between their parentheses and pass them on to the body of the function, which then runs on them, and "replaces" the instance of that function with the return value.

that is, addTwo(1, 9) and 10 can be read the same way (I'm simplifying here a lot), as can addTwo(x, y) and x+y.

addTwo just looks like this:

def addTwo(first, second):
    sum = first + second
    return sum

though most people would just return first + second and otherwise not have a function body.

so the running program would be

def addTwo(first, second)
    return first + second


def main():   #parameters are optional
    result = addTwo(first, second

main() #since this isn't indented, it gets run and isn't part of the above definitions

if it doesn't work put this at the bottom and just ignore the magic for now. __, that is, two underscores, is known as "dunder" in python if you're searching it, double underscore. in general you shouldn't worry about these until you're already good with the basics

if __name__ == "__main__":
    main ()

I'm just some rando, don't take it as gospel. but those are the things I've collected over the years for helping people get started. basically: don't fear not knowing things, instead see it as a sign that you need to figure out a way to reformulate it as things you can find out, then do the same for each of those sub-things you don't understand. school teaches us not to look stuff up, but at least until you're actively trying to get hired, looking it up is imo one of the best ways to learn. the technical version of "if i don't understand a word in something I'm reading, I look it up in the dictionary"

the other thing is books will often gloss over things only to actually explain them later, so I'll often read a book through first really quickly noting down things that stick out, then go back and actually read the book and do the exercises. Just knowing the structure and how things connect helps a lot, when you start to get lost or it feels like a grind that's a good sign it's time to start going back and applying things.

if you're okay abandoning python, the free code camp JavaScript course is pretty good at being very bite sized increments of practice, too. it says it requires css and html knowledge, but I'd say treat that as i say for books: look up what you're confused by in the html css course, and just use that instead of actually completing html css course, since imo it's really slow going.

If you do choose to do html/css first, only do the first cluster of exercises, everything further down can wait.

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/

I ran through these a year ago when moving from python to JavaScript and found them to be too granular for me, but they seemed excellent for beginners. importantly, they make you type out and do the exercises before you can move on, but they're very small so it's not too bad. you can skip them, I suggest not though. You can do this concurrent to python even, if you want.

python's just as good, I just don't have fresh resources in my head.

anyway, contact info is in my profile and you can always send an ask or whatever but I'll def forget about this thread.

but you're "smart enough", don't think the people who went to engineering schools or cs programs are smarter. they're more knowledgeable, sure, but everyone had to learn. it won't feel like you're learning and often it'll feel like struggle, and that's time to take a break and do anything other than programming. you learn less good if you aren't enjoying it, and solutions come to you when you're doing other things.

also errors aren't failures, they're data -- people hit them all the time, the trick is learning how to read the error messages and doing what they say. a "linter" can help here, too, cornflakes for vscode works pretty well but you may need to pip install flake8. to tweak it, Google "flake8 ignore list file"

Hi, I’m a senior software engineer with 10 years of experience. You asked for help learning to code and I’m here to volunteer. Please feel free to reach out in whatever way best suits you. Ask me anything.