Programming thread

Did Terry have any unironically good programing advice? Besides the fact that you should use an ISO to download an operating system becasue that's how the white man does it.
Yes, he like simplicity. He talked about how niggers value complexity, programmers evaluate simplicity. I've always liked that, and I think about it on a regular basis.
 
What do kiwis think the best learner's first language is?
My first language was Java. I picked up a book and learned it. Now I code in primarily c++ with graphics libraries like SDL & SFML because I enjoy the potential speed and lower level language but I don't care to deal with the graphics when I'll never do that better myself anyway (I like doing things myself but that's too far even for me). Java is great in my opinion because it handles memory for you (in an inelegant way albeit), it's VERY object oriented (some dislike it for that but OOP is useful and easy to learn), it handles the graphics in an easy to understand way, and provides many intuitive standard functions/libraries. Python is the typical go to beginner's language but I've never used it so I can't say anything about it other than what I've heard. Probably comparable to Java. As far as I know it's a slower language, the knowledge learned isnt as interchangeable, and it does a little too much for the dev. The speed of Java has become more comparable to C++ in later years btw. Still slower but it's not bad.
Alternatively, should new learners just jump into a low level language immediatley and build up from the fundamental principles? Asking because a lot of nudevs have asked me where to start and I've essentially told them a simplified version of what I said in the spoiler but I've always been worried about misleading them. I have a unique drive to learn things which most people don't have so processes that work for me often don't work for others.
Python for people who aren't looking to be full time devs and C/C++ otherwise. But I'm also of the opinion that the vast majority of people who say they want to learn how to will come out more or less the "same" with any decently supported language as their first language as long as they stick with it. In my experience, most people who say they're interested won't follow through and "unique drive to learn things" is not that unique in the programming/tech world which is rife with people who do things just to figure stuff out. Many say it's a requirement.

I usually recommend Python to people who say "I want to learn to program" because it has a ton of resources and support coupled with good documentation, is easy to get feedback on as they learn and is useful almost everywhere in the real world.
 
Last edited:
Did I fuck up in any major way?
Improvements, not fuckups:

1) maybe you didn't notice, maybe you intended it that way, but the house has a slight advantage (on a roll 1-100, the player wins at 52 or more); in other words it's RIGGED.

2) the win chance should be a module-level variable: just put
Python:
WIN_CHANCE = 49  # percent
if you want to keep it slightly RIGGED, (or 50 for a fair game), at the top level (meaning outside functions, no offset) in your code, and test for
Python:
game_roll <= WIN_CHANCE

Why a variable? Because it is a parameter, not a physically immutable constant (e.g. the number of dimensions in a 2D image), and you might want to check it or change it, and it's hard to search the code for a number. Sometimes you might want to reuse a parameter and/or change it, and then you'd have to search for a number and for each found instance, determine if it's the win chance or the average number of seshes before the cops arrive to arrest the player on two outstanding warrants. Searching for a name is easier. For a short program and "local" parameters, keep them at the top level in a respective file. For a long program spanning several files, the common parameters are better moved to a dedicated file and imported from there (you can import from your own code, too, not just from someone else's).

Why less than or equal? Because that way you get to explicitly define the win chance of the player, which is what people are most interested in, and this makes for the most simple conditional expression.

Also you might want to print out the game roll, because it's fun for the player to see "by how much" he lost.

What else to do:
1. maybe you think rolling higher should be better, like you originally had it. Now that you're printing out the game roll, it may be confusing for the player to win at 20 and lose at 100. So rewrite the condition, using math, to both use WIN_CHANCE = 49 and to have higher=better.
2. if you keep it RIGGED, eventually the player will notice he's losing on a 50 (or 51 if higher=better). Try to RIG the game in a way that's less obvious to the player.

And do the name guard thing Agent Snigger wrote about, it's important/obligatory. Always always always use it, even for very simple programs.
 
1. maybe you think rolling higher should be better, like you originally had it. Now that you're printing out the game roll, it may be confusing for the player to win at 20 and lose at 100. So rewrite the condition, using math, to both use WIN_CHANCE = 49 and to have higher=better.

Something like this?

Python:
    game_roll = random.randint(1,100)

    win_chance = 49

    while True:

        bet = input("how much would you like to bet?: $")

        try:
            stake = int(bet)

            if stake > game_state.cash:
                print("You don't have that much money!")
            else:
                print(f"You bet ${stake}")

                if game_roll <= win_chance:
                    print(100 - game_roll)
                    print("Yes!")
                    game_state.wins = game_state.wins + 1
                    game_state.cash = game_state.cash + stake
                    print(f"You won ${stake}, \nyour balance is ${game_state.cash}")
                    break
                else:
                    print(100 - game_roll)
                    print("No")
                    game_state.losses = game_state.losses + 1
                    game_state.cash = game_state.cash - stake
                    print(f"You lost ${stake}, \nyour balance is ${game_state.cash}")
                    break
        except ValueError:
            print("Invalid input")

Is there a way to make the roll number slowly tick up in the terminal? Kinda like with Limbo.


I think it would be a good way to build anticipation.


2. if you keep it RIGGED, eventually the player will notice he's losing on a 50 (or 51 if higher=better). Try to RIG the game in a way that's less obvious to the player.

I mean it's mainly based on dice (the version Bossman plays) and that game literally tells you you only have a 49.5% chance of winning. It being so obviously rigged never stopped the Bosssman.
 
Is there a way to make the roll number slowly tick up in the terminal? Kinda like with Limbo.
Yes, you would need to combine sleep and ANSI escape sequences.
You want the one that deletes back to the start of the line.

I would say "try ncurses and make a TUI", but don't because NCurses is shit. I'm sure that there is some python TUI library that's fine, but I can't give you a recommendation on that front.
 
  • Like
Reactions: Marvin
I would say "try ncurses and make a TUI", but don't because NCurses is shit. I'm sure that there is some python TUI library that's fine, but I can't give you a recommendation on that front.
Termbox is pretty much always the way to go instead of ncurses these days. My chat client uses a TUI library that applies the termbox concepts nicely.
 
Yes, you would need to combine sleep and ANSI escape sequences.
You want the one that deletes back to the start of the line.

I would say "try ncurses and make a TUI", but don't because NCurses is shit. I'm sure that there is some python TUI library that's fine, but I can't give you a recommendation on that front.
Like this?

Python:
    game_roll = random.randint(1,100)

    win_chance = 49

    display_roll = 100 - game_roll

    roll_count = 1

    while True:

        bet = input("how much would you like to bet?: $")

        try:
            stake = int(bet)

            if stake > game_state.cash:
                print("You don't have that much money!")
            else:
                print(f"You bet ${stake}")

                if game_roll <= win_chance:
                    while roll_count < display_roll + 1:
                        print(f"{roll_count}\r", end="")
                        time.sleep(0.02)
                        roll_count = roll_count + 1
                    print("\nYes!")
                    game_state.wins = game_state.wins + 1
                    game_state.cash = game_state.cash + stake
                    print(f"You won ${stake}, \nyour balance is ${game_state.cash}")
                    break
                else:
                    while roll_count < display_roll + 1:
                        print(f"{roll_count}\r", end="")
                        time.sleep(0.02)
                        roll_count = roll_count + 1
                    print("\nNo")
                    game_state.losses = game_state.losses + 1
                    game_state.cash = game_state.cash - stake
                    print(f"You lost ${stake}, \nyour balance is ${game_state.cash}")
                    break
        except ValueError:
            print("Invalid input")

This feels kinda ham fisted, but it works. I should probably go and add short delays to all the prints, it just looks nicer.

Edit: I found a bug, if the game rolls a 100 it doesn't display anything. I need to fix that.
 
Last edited:
Fixed it

Python:
    game_roll = random.randint(1,100)
    
    win_chance = 49

    display_roll = 100 - game_roll

    roll_count = 1

    while True:

        bet = input("how much would you like to bet?: $")
        time.sleep(0.2)

        try:
            stake = int(bet)

            if stake > game_state.cash:
                print("You don't have that much money!")
                time.sleep(0.2)
            else:
                print(f"You bet ${stake}")

                if game_roll <= win_chance:
                    print("0",end="")
                    while roll_count < display_roll + 1:
                        print(f"\r{roll_count}", end="")
                        time.sleep(0.02)
                        roll_count = roll_count + 1
                    print("\nYes!")
                    time.sleep(0.2)
                    game_state.wins = game_state.wins + 1
                    game_state.cash = game_state.cash + stake
                    print(f"You won ${stake}")
                    time.sleep(0.2)
                    print(f"your balance is ${game_state.cash}")
                    time.sleep(0.2)
                    break
                else:
                    print("0",end="")
                    while roll_count < display_roll + 1:
                        print(f"\r{roll_count}", end="")
                        time.sleep(0.02)
                        roll_count = roll_count + 1
                    print("\nNo")
                    game_state.losses = game_state.losses + 1
                    game_state.cash = game_state.cash - stake
                    print(f"You lost ${stake}")
                    time.sleep(0.2)
                    print(f"your balance is ${game_state.cash}")
                    time.sleep(0.2)
                    break
        except ValueError:
            print("Invalid input")

But I did find printing zero like that created an issue where if you rolled a single digit number it would print 51 if you rolled a 5, 91 if you rolled a 9 etc. but then I found out I just had to change "print(f"{roll_count}\r", end="")" to "print(f"\r{roll_count}", end="")" and that fixed the issue. I made it so that both the winning counter and the losing counter print zero so if you see zero for one frame it won't spoil if you won or lost. Also I added a bunch of delays for the text, I think it really makes the game flow better.

I'm not sure how applicable this stuff is to stuff that will get me a job, but I'm learning and it's really fun.
 
  • Like
Reactions: Not Real and Marvin
I'm not sure how applicable this stuff is to stuff that will get me a job, but I'm learning and it's really fun.
You're learning the fundamentals right now, pretty much everything will be applicable, whether it's creating functions, creating classes, or even printing something, it will be at least a little bit useful. I recommend, when you feel comfortable enough with Python, to switch to C (not C++). So instead of focusing on problem solving, you'll learn what the computer does when solving the problem (It's literally pretty much the same except variables cannot switch types and you have to manage memory yourself sometimes)
 
when you feel comfortable enough with Python
How will I know that I'm comfortable enough? What should I be able to do in python? Are there projects you can recommend that will help get me to this point? I feel like I'm kinda done with the gamba game, at least for now, I want to move on.
 
How will I know that I'm comfortable enough? What should I be able to do in python? Are there projects you can recommend that will help get me to this point? I feel like I'm kinda done with the gamba game, at least for now, I want to move on.
The secret is that you're never ready. I think I'm pretty good at programming and I know I'm not ready for the types of tasks I take on: but that's the secret in development, nothing is ever written in stone, you will always be learning. And that's part of the fun of programming.

The next project you should take on is one that interests you. Do you want to make games? Do you want to make a website or app? Do you have a problem you encounter in life that could be automated? Do you want to make a tool?

The best way to learn is by cutting your teeth on projects that interest you. Tell us what you want to make and we can point you to what you might want to learn.

Apropos the best language to start, the best language to start in is going to be different based on what the learner wants to do (see above advice).

If I were to write a programme teaching programming something I should damn well get around to doing as much as I muse about it, I would probably teach Lua. Getting something up and running visually in Love2D is joyous. The downside of Lua is that the platform is very poor, since it's meant to be embedded.
 
Last edited:
How will I know that I'm comfortable enough? What should I be able to do in python? Are there projects you can recommend that will help get me to this point? I feel like I'm kinda done with the gamba game, at least for now, I want to move on.
You'll know. The thing about programming is that which language you use doesn't matter (there's a reason why most languages people use are called "C-like"). What you're learning right now, apart from learning Python, is that you're currently learning problem solving. You're learning how to break a problem down into smaller and smaller chunks until they're small enough you're able to describe them to a lightning-powered rock. What programming language you use doesn't matter, it just makes some parts easier, some parts harder.

The best projects are the ones you want to work on. I like solving problems from Advent of Code (at least first few days) and The Weekly Challenge (the owner posts 2 relatively simple problems every week), but I really recommend branching out to something you yourself want to work on. For example make a Pac-Man clone if you like Pac-Man, do a Tetris clone if you like Tetris, etc. If you're like "damn, I'm really feeling like I wanna do X", then do X, there's no set path to follow.
 
The secret is that you're never ready. I think I'm pretty good at programming and I know I'm not ready for the types of tasks I take on: but that's the secret in development, nothing is ever written in stone, you will always be learning. And that's part of the fun of programming.

The next project you should take on is one that interests you. Do you want to make games? Do you want to make a website or app? Do you have a problem you encounter in life that could be automated? Do you want to make a tool?

The best way to learn is by cutting your teeth on projects that interest you. Tell us what you want to make and we can point you to what you might want to learn.

Apropos the best language to start, the best language to start in is going to be different based on what the learner wants to do (see above advice).

If I were to write a programme teaching programming something I should damn well get around to doing as much as I muse about it, I would probably teach Lua. Getting something up and running visually in Love2D is joyous. The downside of Lua is that the platform is very poor, since it's meant to be embedded.
Right now making games like this is what interests me. They feel low stakes and it's fun to test them out. What would be the next step up from the gamba game? Also I'd kinda like to work with GUIs eventually.

Speaking of the gamba game, here's the updated version with all the sleeps, if anyone is interested.
Python:
import random

import time

class Gamestate:
    def __init__(self,wins=0,losses=0,cash=100):
        self.wins = wins
        self.losses = losses
        self.cash = cash

    @staticmethod
    def start_game():
        return Gamestate()

def gamba_game(game_state):
    
    game_roll = random.randint(1,100)
    win_chance = 49

    display_roll = 100 - game_roll

    roll_count = 1

    while True:

        bet = input("how much would you like to bet?: $")
        time.sleep(0.2)

        try:
            stake = int(bet)

            if stake > game_state.cash:
                print("You don't have that much money!")
                time.sleep(0.2)
            else:
                print(f"You bet ${stake}")

                if game_roll <= win_chance:
                    print("0",end="")
                    while roll_count < display_roll + 1:
                        print(f"\r{roll_count}", end="")
                        time.sleep(0.02)
                        roll_count = roll_count + 1
                    print("\nYes!")
                    time.sleep(0.2)
                    game_state.wins = game_state.wins + 1
                    game_state.cash = game_state.cash + stake
                    print(f"You won ${stake}")
                    time.sleep(0.2)
                    print(f"your balance is ${game_state.cash}")
                    time.sleep(0.2)
                    break
                else:
                    print("0",end="")
                    while roll_count < display_roll + 1:
                        print(f"\r{roll_count}", end="")
                        time.sleep(0.02)
                        roll_count = roll_count + 1
                    print("\nNo")
                    game_state.losses = game_state.losses + 1
                    game_state.cash = game_state.cash - stake
                    print(f"You lost ${stake}")
                    time.sleep(0.2)
                    print(f"your balance is ${game_state.cash}")
                    time.sleep(0.2)
                    break
        except ValueError:
            print("Invalid input")

def gamba_start(game_state):
    
    print(f"Welcome to the casino!")
    time.sleep(0.2)
    print(f"You have ${game_state.cash}.")
    time.sleep(0.2)

    while True:
        play =  input(f"Would you like to play?(yes/no): ")
        time.sleep(0.2)
        
        play = play.lower()

        match play:
            case "yes"|"y":
                gamba_sesh(game_state)
                break
            case "no"|"n":
                print("That's probably a good idea")
                break
            case _:
                print("Invalid input, please try again")

def gamba_sesh(game_state):

    gamba_game(game_state)

    while True:
        
        if game_state.cash <= 0:
            print("Dude I just lost it all")
            time.sleep(0.2)
            print(f"wins {game_state.wins}")
            time.sleep(0.2)
            print(f"losses {game_state.losses}")
            break
        else:
            play_again = input("Play again? (yes/no): ")
            time.sleep(0.2)

            play_again = play_again.lower()
            
            match play_again:
                case "yes"|"y":
                    gamba_game(game_state)
                case "i need crack":
                    print("Oh shit guys I gotta go!")
                    break
                case _:
                    print("One more and I'm out!")
                    time.sleep(0.2)
                    gamba_game(game_state)

game_state_start = Gamestate.start_game()
gamba_start(game_state_start)
 
n my experience, most people who say they're interested won't follow through and "unique drive to learn things" is not that unique in the programming/tech world which is rife with people who do things just to figure stuff out.
This is definitely true. Most of the people I've dealt with who I couldn't see sticking with coding had the issue of wanting the end result of coding but not caring about the process, so they learn as little as they can to achieve their intended result (or asking someone like me to do their work for them...). That just doesn't work with coding. It is a necessity to stick it out and gain a more complete knowledge of the language. There's no shortucts and if there's no interest then there's no drive. I find that applies to technical things very broadly too (Most people are smart enough for X but they dont have enough of passion for it).
 
Back