Programming thread

  • 🐕 I am attempting to get the site runnning as fast as possible. If you are experiencing slow page load times, please report it.
Racket is more like a logical extension to Scheme than an implementation of it.
I believe the original concept behind Racket, which had a different name at the time, was more to be more just a typical Scheme implementation and it has since grown into the plurality it is now
Haskell is fun too.
I have a friend who is a comp sci researcher in Texas and he was using Haskell right up to the point that he found out that implementing a fairly trivial sieve of Eratosthenes algorithm had to be the subject of an entire research paper at which point he was like "this is really fucking gay"
I'll say that I think if anything like memory or performance are a big issue, Python is generally not the right language.
Python definitely sees deployment in industry for those things as long as critical areas are sped up in some way or another
Well that offers a good explanation for the bug I had in Python when I was doing Recursion.
That depends. Python is really on the nose about these things and will throw a RecursionError exception which I'm not sure sees any other use. Was that the case?
 
  • Like
Reactions: y a t s
That depends. Python is really on the nose about these things and will throw a RecursionError exception which I'm not sure sees any other use. Was that the case?
Nope There was no error in the Runtime itself. It ran without throwing out any errors.

The bug was basically something that should have been done in the 2nd recursive step was done first, and the first step was skipped.

I had everything in an order that it should have worked correctly if it ran in the order it was written to run in but based on the result I was getting I could tell it was skipping the first recursive step. I moved some things around and did some other things differently and then it worked perfectly.
 
  • Thunk-Provoking
Reactions: Belisarius Cawl
The impetus for me to ask this question is basically that I really don't like too much abstraction. OOP is fast to write complex abstractions for but hard to understand what is going on if you didn't write it. Functional paradigms IMO are easier to understand because you do something piece by piece if I am understanding correctly. Which is why I have never gravitated towards things like classes or traits despite them existing in the language I use.
I think it's all about the degree to which one uses these paradigms. Classes are useful for organization, especially in languages that don't use header files, but they can quickly become a tangled mess with layers of inheritance. They're great for libraries, because you can provide an abstracted interface to the user and handle all the plumbing behind the scenes. Go does it in a really elegant way with struct composition and interfaces. Functional has a ton of benefits like those mentioned in other posts, but it can easily become a tangled mess when you start passing function references around.

My main problem with classes is they bring all the issues of global variables. You can define encapsulated globals in C by leaving them out of the header file, but it's bad practice to rely on them. Yet, C++ puts a new coat of paint on the same core idea and suddenly it's standard practice. Lunacy.

Forgot about this:
I was doing a lot of Functional stuff especially because I really like using Numpy and I unironically think Vectors are easier to make than loops. I could use stuff like Classes but I inherently dislike them and find the piece by piece approach of functional programming to be easier to think about because I think it can be broken into smaller pieces.
If you're doing mathematical work, functional programming will be quite intuitive. Purely functional approaches work in a more mathy sense, since it's all a bunch of function compositions. As such, functional implementations are much easier to prove mathematically. You're working with vectors, and anyone who knows a bit of linear algebra will know that you can express all of these compositions as the multiplication of their transformation matrices. So an approach where you transform a vector a bunch of times will feel more intuitive for this use case. That's essentially what you're doing.
 
Last edited:
My main problem with classes is they bring all the issues of global variables. You can define encapsulated globals in C by leaving them out of the header file, but it's bad practice to rely on them. Yet, C++ puts a new coat of paint on the same core idea and suddenly it's standard practice. Lunacy.
You'd probably hate R. It has a history of all sorts of questionable practices including an utterly polluted global namespace. It starts with the base installation with datasets like mtcars just loaded in there by default, in part presumably for compatibility with a commercial product no one uses anymore called S, and then it just keeps getting worse when you load more packages. Disambiguation with pkg::name syntax is always possible but overall there's a lot about R that is just sloppy. Nevertheless I enjoy using R, especially for visualization vs. Python, and the silver lining with the global namespace pollution is that things are much more concise than they would have been if things were sane.
 
I had to put up with R for a long time while getting my doctorate. All I can say is it sure beats using MATLAB.
Fuck MATLAB.
I'm sure there are areas where MATLAB alternatives lag behind said product but if that's not a problem, consider SageMath. From the website:
SageMath is a free open-source mathematics software system licensed under the GPL. It builds on top of many existing open-source packages: NumPy, SciPy, matplotlib, Sympy, Maxima, GAP, FLINT, R and many more. Access their combined power through a common, Python-based language or directly via interfaces or wrappers.

Mission: Creating a viable free open source alternative to Magma, Maple, Mathematica and Matlab.
There is a unified syntax hooking all these packages together that is almost identical to standard Python and in fact transpiles to Python. Here's a quick comparison. Standard Python:
Python:
from math import e, pi
e**(pi * complex(0, 1)) + 1
The output is 1.2246467991473532e-16j. Gayyyyy. Here's the equivalent in SageMath:
Python:
e^(pi*i) + 1
The output is what it should be: 0. I've primarily used SageMath for doing number theory problems easily and quickly but as you can see it goes well beyond that.
 
Forgot about this:
If you're doing mathematical work, functional programming will be quite intuitive. Purely functional approaches work in a more mathy sense, since it's all a bunch of function compositions. As such, functional implementations are much easier to prove mathematically. You're working with vectors, and anyone who knows a bit of linear algebra will know that you can express all of these compositions as the multiplication of their transformation matrices. So an approach where you transform a vector a bunch of times will feel more intuitive for this use case. That's essentially what you're doing.
That's what I wanted to hear basically. It was an Idea I had one day and I had no idea if it made sense or was completely retarded. I like that it would work but there isn't really a good reason for it and so it is basically retarded,

Fuck MATLAB.
I don't know if they just made it better, but I don't see it deserving the hate it receives. The fact it isn't open source and you have to pay for it is monumentally retarded, but it worked okay during the class I had to take with it in college. Just seemed like a different version of Python with semicolons and some different syntax.
 
  • Like
Reactions: ellroy and y a t s
Realistically, it's best to use tail recursion as a rule instead of a case by case basis. Plus, I find TCO much easier to chain together in my head and reason about at a glance, since it works similarly to a simple loop.
Properly implemented TCO is like a named loop construct, except it's safe with regards to variable scoping.
I think it's all about the degree to which one uses these paradigms. Classes are useful for organization, especially in languages that don't use header files, but they can quickly become a tangled mess with layers of inheritance. They're great for libraries, because you can provide an abstracted interface to the user and handle all the plumbing behind the scenes. Go does it in a really elegant way with struct composition and interfaces.
I mean, you could argue that what Go does isn't strictly OOP / Classes, because there's no automatic promotion of types.

I do like how Go does it though. The best kind of OOP is not-OOP.
 
I’m pleasantly surprised how much fun I’m having programming in C. Admittedly, I’ve just now finished chapter one of K&R so maybe I’m just in the easy phase. Still I managed to write a little slot machine program in C inspired by bossmanjack! Is it good code? No, but it works.
C:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

void slots(double startAm);

int main() {
    //printf("Hello, World!\n");

    //declare variable
    double startingMon = 4000.00;
    //call slots
    slots(startingMon);
    return 0;
}

void slots(double startAm){
    printf("Test your luck! Current balance: %.2f", startAm);

    char Cards[] = "123456789JQKA";
    int isGo;

    time_t t1;
    int num = 100;

    int numCards = strlen(Cards) - 1;
    int s1, s2, s3;
    s1 = s2 = s3 = 0;

    srand((unsigned) time (&t1));

    while((isGo = getchar()) == '\n' && isGo != EOF && startAm > 0.0){
        startAm -= 20.00;
        printf("Balance: %.2f\n", startAm);
        s1 = rand() % numCards;
        s2 = rand() % numCards;
        s3 = rand() % numCards;
        printf("[%c]-[%c]-[%c]", Cards[s1],Cards[s2],Cards[s3]);
        //printf("%d %d %d", s1, s2, s3);
        int check = ((s1 == s2) && (s2 == s3) && (s1 == s3));
        //printf("%d\n", check);

        if(check == 1){
            printf("Jackpot! Congratulations! Try Again?");
            startAm += (startAm * 0.3);
        }
        else {
            printf("No dice! Try again.\n");
        }
        if(startAm == 0.0){
            printf("Tough Luck! Insufficient funds!");
        }
    }

}
 
I’m pleasantly surprised how much fun I’m having programming in C. Admittedly, I’ve just now finished chapter one of K&R so maybe I’m just in the easy phase. Still I managed to write a little slot machine program in C inspired by bossmanjack! Is it good code? No, but it works.
C:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

void slots(double startAm);

int main() {
    //printf("Hello, World!\n");

    //declare variable
    double startingMon = 4000.00;
    //call slots
    slots(startingMon);
    return 0;
}

void slots(double startAm){
    printf("Test your luck! Current balance: %.2f", startAm);

    char Cards[] = "123456789JQKA";
    int isGo;

    time_t t1;
    int num = 100;

    int numCards = strlen(Cards) - 1;
    int s1, s2, s3;
    s1 = s2 = s3 = 0;

    srand((unsigned) time (&t1));

    while((isGo = getchar()) == '\n' && isGo != EOF && startAm > 0.0){
        startAm -= 20.00;
        printf("Balance: %.2f\n", startAm);
        s1 = rand() % numCards;
        s2 = rand() % numCards;
        s3 = rand() % numCards;
        printf("[%c]-[%c]-[%c]", Cards[s1],Cards[s2],Cards[s3]);
        //printf("%d %d %d", s1, s2, s3);
        int check = ((s1 == s2) && (s2 == s3) && (s1 == s3));
        //printf("%d\n", check);

        if(check == 1){
            printf("Jackpot! Congratulations! Try Again?");
            startAm += (startAm * 0.3);
        }
        else {
            printf("No dice! Try again.\n");
        }
        if(startAm == 0.0){
            printf("Tough Luck! Insufficient funds!");
        }
    }

}
Missing the 10 card of each suit, also wtf isn't Ace a 1. 7/10
 
I’m pleasantly surprised how much fun I’m having programming in C. Admittedly, I’ve just now finished chapter one of K&R so maybe I’m just in the easy phase. Still I managed to write a little slot machine program in C inspired by bossmanjack! Is it good code? No, but it works.
Your code allows for betting more than you have. Each play will cost 20.00, but the slot routine repeats as long as the balance is strictly greater than zero.

You're probably not encountering this bug because your starting money is a multiple of 20, so you'd only have an amount that's not a multiple of 20 if you've won a Jackpot (which might or might not be a multiple of 20). If you run the program enough times, though, it'll eventually happen.
 
Missing the 10 card of each suit, also wtf isn't Ace a 1. 7/10
Fuck you’re right, can’t believe I missed that. Easy fix though, I can just make the ‘1’ represent ten.

Your code allows for betting more than you have. Each play will cost 20.00, but the slot routine repeats as long as the balance is strictly greater than zero.

You're probably not encountering this bug because your starting money is a multiple of 20, so you'd only have an amount that's not a multiple of 20 if you've won a Jackpot (which might or might not be a multiple of 20). If you run the program enough times, though, it'll eventually happen.
Forgot about that, I realized that long after I finished my code. Again easy fix.

But alas I must commit sudoku for I have brought dishonor to BMJ’s good name!
 
I’m pleasantly surprised how much fun I’m having programming in C. Admittedly, I’ve just now finished chapter one of K&R so maybe I’m just in the easy phase. Still I managed to write a little slot machine program in C inspired by bossmanjack! Is it good code? No, but it works.
Happy to hear you're enjoying it. It's a wonderful language. Aside from a few small bugs mentioned above, your program looks pretty good. It's way nicer and easier to read than a lot of stuff I have seen from 2nd year CS students; pat yourself on the back.

Some tips:
int check = ((s1 == s2) && (s2 == s3) && (s1 == s3));
Because of the transitive property of equality, you don't need to check s1 == s3 since it's implied by the first 2 conditions.

if(check == 1)
In C, booleans are technically just integers under the hood, as demonstrated by this comparison to 1. As such, 0 is considered false and non-zero values are considered true, so you can shorten this conditional to if (check) to achieve the same result.

When you get around to using pointers, you can take advantage of 0 being treated as false to quickly check for null (0x0) pointers. If this makes no sense right now, it will pretty soon as you keep learning; don't worry about it.

while((isGo = getchar()) == '\n' && isGo != EOF && startAm > 0.0)
If the char from getchar() is a '\n', that implies getchar() didn't return an EOF.
Regardless, I would probably do something like this as my loop layout:
C:
while ((isGo = getchar()) != EOF) {
    if (startAm < 20.0) {
        // Don't forget your newlines.
        printf("Tough Luck! Insufficient funds!\n");
        // Could be break instead of return, but I don't like using it.
        return;
    }
    startAm -= 20.00;
    printf("Balance: %.2f\n", startAm);
   
    s1 = rand() % numCards;
    s2 = rand() % numCards;
    s3 = rand() % numCards;
    printf("[%c]-[%c]-[%c]\n", Cards[s1],Cards[s2],Cards[s3]);

    if ((s1 == s2) && (s2 == s3)) {
        printf("Jackpot! Congratulations! Try Again?\n");
        startAm += (startAm * 0.3);
    } else {
        printf("No dice! Try again.\n");
    }
}
The user can signal EOF using Ctrl-D to quit. Or they can do a SIGINT.
 
Last edited:
I’m pleasantly surprised how much fun I’m having programming in C. Admittedly, I’ve just now finished chapter one of K&R so maybe I’m just in the easy phase. Still I managed to write a little slot machine program in C inspired by bossmanjack! Is it good code? No, but it works.
C:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

void slots(double startAm);

int main() {
    //printf("Hello, World!\n");

    //declare variable
    double startingMon = 4000.00;
    //call slots
    slots(startingMon);
    return 0;
}

void slots(double startAm){
    printf("Test your luck! Current balance: %.2f", startAm);

    char Cards[] = "123456789JQKA";
    int isGo;

    time_t t1;
    int num = 100;

    int numCards = strlen(Cards) - 1;
    int s1, s2, s3;
    s1 = s2 = s3 = 0;

    srand((unsigned) time (&t1));

    while((isGo = getchar()) == '\n' && isGo != EOF && startAm > 0.0){
        startAm -= 20.00;
        printf("Balance: %.2f\n", startAm);
        s1 = rand() % numCards;
        s2 = rand() % numCards;
        s3 = rand() % numCards;
        printf("[%c]-[%c]-[%c]", Cards[s1],Cards[s2],Cards[s3]);
        //printf("%d %d %d", s1, s2, s3);
        int check = ((s1 == s2) && (s2 == s3) && (s1 == s3));
        //printf("%d\n", check);

        if(check == 1){
            printf("Jackpot! Congratulations! Try Again?");
            startAm += (startAm * 0.3);
        }
        else {
            printf("No dice! Try again.\n");
        }
        if(startAm == 0.0){
            printf("Tough Luck! Insufficient funds!");
        }
    }

}
Another tip: if you move main so that it comes after slots, you'll no longer need to pre-declare slots.

Also, it's a good idea to make functions "static" if they're only accessible from one source file. It makes it so the compiler can do some optimizations.
 
I'll throw in one nitpick of my own:
s1 = rand() % numCards;
This used to be one of the things they specifically warned you not to do, because simplistic pseudorandom number generators don't give very random results at all when used this way - the low bits in particular weren't great. Nowadays it depends on exactly what algorithm is sitting behind your rand().
On Windows, rand_s is hooked up to a better randomness source, and on Linux you can read dev/urandom or dev/random.

Not that it matters if you're just having some fun, but it's something to make a note of.
 
I'll throw in one nitpick of my own:

This used to be one of the things they specifically warned you not to do, because simplistic pseudorandom number generators don't give very random results at all when used this way - the low bits in particular weren't great. Nowadays it depends on exactly what algorithm is sitting behind your rand().
On Windows, rand_s is hooked up to a better randomness source, and on Linux you can read dev/urandom or dev/random.

Not that it matters if you're just having some fun, but it's something to make a note of.
Your average single-player game doesn't really need cryptographic-grade randomness. It's still a thing that he should be aware of, though. For platform-agnostic secure random numbers I'd recommend using libraries: Modern computer systems generally come with cryptography libraries that can be dynamically linked to for almost free, and I'm almost completely sure they all expose functionality for creating secure random numbers, since they all use it internally. OpenSSL is the most common library of this type.
 
I've been working on a bossman themed "casino" written in C# using Raylib with a bunch of stake/bc.game inspired games, so far I have made: a dice clone, plinko, wheel and mines. I just completed my plinko clone which required me to write a shitty little physics engine, I am sure its incorrect but I just did what felt correct ish in my head of how a interaction should work, the rigger mutts will appear if a :lossmanjack: gets too close to a more than 2x win and will vacuum it back towards the center

my favorite clone is probably the wheel since its incredibly silly and I managed to get the trig working at 4 in the morning for the eye transformations

another game is mines or my clone "trappy turds", its just mines but with a crackrock hidden in there that will reveal a bunch of random tiles if its found. Only thing really note worthy about this one is that the flipping effect is achieved by shifting width and position.

Currently I am working on ACK-city which will be a rip city clone (slot) ackcity.png
The main challenge of this one will be that I want soft body physics for the tranny so I will have to generate a mesh and write a tool so I can vertex paint, so that will probably be interesting to implement, so far I have a procedural rope done.

1712320284920.png
 
Last edited:
Back