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.
i've been horrifically unproductive for months and idk what to do about it. I've been waiting on my hands for a bunch of shit to fall through and it's still at least another month out.
Try doing some hackerrank, leetcode, or project euler problems. It helps me feel less like programming is a job and more of an intellectual exercise. Coding something retarded but fun also helps.
This book isn't strictly programming but it's really fun if you enjoy CS, there are PDFs online
1651496258927.png
 
i've been horrifically unproductive for months and idk what to do about it. I've been waiting on my hands for a bunch of shit to fall through and it's still at least another month out.
Most helpful thing I've found is finding time to turn off my phone and notifications/email/slack and just write out a couple easy things I want to do, and that usually then rolls into spending a lot of time working on whatever personal project it is. Meditation + cold showers help a lot to.

I remember you saying something about getting stuck, which caused you to lose interest. Try approaching different things and breaking them into comically small steps on a to-do list, like "write x function, write documentation for y function". I find it's hard to start when a problem seems overwhelming, and breaking it down into really tiny parts helps a lot.

Btw, are you accepting new help for the forum software project?
 
  • Like
Reactions: Knight of the Rope
Btw, are you accepting new help for the forum software project?
Yes, it is in Rust and my current thing is writing the permission suite. I'm new to a lot of the project and I feel like at this point I should be taking the time to set up the phpBB/Forum/Discord style user/group/area permission flag system but that's so much work and is such a fundamental challenge that I just can't wrap my mind around it and I'm not confident enough in my approach to bother.
 
Yes, it is in Rust and my current thing is writing the permission suite. I'm new to a lot of the project and I feel like at this point I should be taking the time to set up the phpBB/Forum/Discord style user/group/area permission flag system but that's so much work and is such a fundamental challenge that I just can't wrap my mind around it and I'm not confident enough in my approach to bother.
What's the gist of the permission suite you're looking to implement?
 
phpBB/Forum/Discord style user/group/area permission flag system but that's so much work and is such a fundamental challenge that I just can't wrap my mind around it and I'm not confident enough in my approach to bother
unless i'm mistaken, you just define individual permissions as bit fields/flags , then you can define specific user permissions by ORing them together. from there, individual permissions can be checked as a boolean using AND.

e.g.
C++:
// 00000001 shifted left 0, so 00000001
#define PERM_A (1<<0)
// 00000001 shifted left 1, so 00000010
#define PERM_B (1<<1)
//etc.
#define PERM_C (1<<2)

// imagine user->perms is an 8-bit integer type with the bit representation 00000000

user->perms = PERM_A | PERM_C; // user->perms is now 00000101

ASSERT(user->perms & PERM_A); // succeeds
ASSERT(user->perms & PERM_C); // succeeds
ASSERT(user->perms & PERM_B); // fails
translated to trannylang, you should then just be able to check for individual flags wherever you checked for a hierarchical status (i.e. mod/admin/etc.) before (instead of checking for some is_mod value, check for the required perms).
 
What's the best resource for learning C++? I know Java well enough to kludge code and I picked up html reasonably enough using Free Code Camp, but trying C++ on different websites that offer it just feels uninspiring for some reason and many of them give you very little to work with before asking for payment. Don't know why I'm struggling with it so much either, just feels like a lack of motivation.
 
  • Thunk-Provoking
Reactions: Knight of the Rope
What's the best resource for learning C++? I know Java well enough to kludge code and I picked up html reasonably enough using Free Code Camp, but trying C++ on different websites that offer it just feels uninspiring for some reason and many of them give you very little to work with before asking for payment. Don't know why I'm struggling with it so much either, just feels like a lack of motivation.
I can't really speak to book/tutorial recommendations (I was a fan of the Malik one myself but that's probably outdated as fuck by now because I'm a geezer and haven't touched C++ in almost a decade). But you definitely want to be practicing programming in a local environment for C++ I would say, rather than on repl.it or some other Internet service or whatever it is that you're looking at. Even something basic like VSCode and g++ on WSL would be a better environment for learning than webshit.
 
  • Informative
Reactions: Retink
I can't really speak to book/tutorial recommendations (I was a fan of the Malik one myself but that's probably outdated as fuck by now because I'm a geezer and haven't touched C++ in almost a decade). But you definitely want to be practicing programming in a local environment for C++ I would say, rather than on repl.it or some other Internet service or whatever it is that you're looking at. Even something basic like VSCode and g++ on WSL would be a better environment for learning than webshit.
That might be a good point, the way I learned Java back in the day was just following a book and using Eclipse from what I remember and it stuck with me way better after all of this time than the html I picked up off of Free Code Camp. I like the interactive aspect of how some websites do it, but that might also just be too much handholding that makes it harder to build up the familiarity with the syntax.

One thing I'd really like to find is something that gives you projects to do as a beginner as I probably learned the most from the projects at the end of Free Code Camp as opposed to the actual lessons. Something about doing things with a goal help a lot. Would the book you recommended have something like that?
 
  • Like
Reactions: Knight of the Rope
Yes, it is in Rust and my current thing is writing the permission suite. I'm new to a lot of the project and I feel like at this point I should be taking the time to set up the phpBB/Forum/Discord style user/group/area permission flag system but that's so much work and is such a fundamental challenge that I just can't wrap my mind around it and I'm not confident enough in my approach to bother.
Possible approach is to abstract user groups from actions.

In the software you have permissions for specific actions. etc: delete post, edit post, ban user.

Then you have a table in the database for each user group, specifying what they can and can not do. You can have one group, "owner" (which consists of just you) which can do anything. Another group "moderators", that can do some things (ban user) but maybe not others (delete thread with more than 500 posts). And the final group "user", that can just post. You can then assign users to one or multiple user groups, since user groups are always additive. Upside is you can add user groups or permissions at any time.
 
What's the best resource for learning C++? I know Java well enough to kludge code and I picked up html reasonably enough using Free Code Camp, but trying C++ on different websites that offer it just feels uninspiring for some reason and many of them give you very little to work with before asking for payment. Don't know why I'm struggling with it so much either, just feels like a lack of motivation.
learncpp.com has been kept up to date by a couple of spergs for a long time and has been continually reworked to teach c++ better. Definitely would recommend it.

C++ is kind of a fucking nightmare language though. I would highly recommend learning C first, and then writing C-style code in C++.

C++ might just not be the language for you though. Why do you want to program? Do you want to make things? What kind of things? Are you interested more in the math/problem solving aspects of programming?

Tbh after I learned Rust I don't think I'll ever program C++ again. Even something as simple as moving a file in C++ can easily have vulnerabilities. Also traits/typeclasses are fucking based and are far better than classes.
 
  • Like
Reactions: Retink
C++ might just not be the language for you though. Why do you want to program? Do you want to make things? What kind of things? Are you interested more in the math/problem solving aspects of programming?
That's actually a hard question to answer, as there's no particular why, it's more that I think being able to code at this point is essentially like being able to read back when literacy was still not widespread, it's something that will become more and more important and if you don't understand it you're doing a disservice to yourself. As for why C++ from what I understand it's the most versatile, so if I don't have an exact goal it just makes sense to go for a more flexible option as the various fields I looked up seem to all mention it as a good option while other languages might be widely applicable they aren't as universal.

Math is something I like, it's partially why I could get the degree that I did as I was shit at the subject but had enough of a fundamental understanding of math to stumble my way through. I would be interested in looking into machine learning and AI, but that's further down the line. I'd also say not having exact reasons is a big part of the problem, as I took Java back in college as an optional set of courses and liked it but don't really use it beyond the rare occasion and html I haven't used at all with the rare exception of inspecting code on websites for minor bug fixes when bored. That's why I want to find a language I can just find more application for and really grind at, as so far it's been a sort of learn the basics and then meander with low improvement unless I'm actually working on something where I need to apply those skills and that's not particularly common these days.
 
That's actually a hard question to answer, as there's no particular why, it's more that I think being able to code at this point is essentially like being able to read back when literacy was still not widespread, it's something that will become more and more important and if you don't understand it you're doing a disservice to yourself. As for why C++ from what I understand it's the most versatile, so if I don't have an exact goal it just makes sense to go for a more flexible option as the various fields I looked up seem to all mention it as a good option while other languages might be widely applicable they aren't as universal.

Math is something I like, it's partially why I could get the degree that I did as I was shit at the subject but had enough of a fundamental understanding of math to stumble my way through. I would be interested in looking into machine learning and AI, but that's further down the line. I'd also say not having exact reasons is a big part of the problem, as I took Java back in college as an optional set of courses and liked it but don't really use it beyond the rare occasion and html I haven't used at all with the rare exception of inspecting code on websites for minor bug fixes when bored. That's why I want to find a language I can just find more application for and really grind at, as so far it's been a sort of learn the basics and then meander with low improvement unless I'm actually working on something where I need to apply those skills and that's not particularly common these days.
If you enjoy math I'd suggest learning Haskell, or some other functional language like Clojure. The abstractions Haskell provides are a ton of fun if you are someone who enjoys thinking abstractly and learning abstract concepts. I know for me thinking in terms of pure functions comes much more naturally than thinking about state.

For example, a basic Fibonacci sequence, the "hello world" of Haskell.

Code:
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)

Read in plain english, the definition is "the first two numbers of the Fibonacci sequence are 0 and 1. Every other number in the Fibonacci sequence is the sum of the precious two". It's comically simple.

Also don't let retards tell you Haskell can't be fast. The GHC is called state-of-the-art for a reason, and there's a reason a bunch of compilers are written in Haskell, it's pretty fucking fast. Just learn when to use eager evaluation and make sure recursive functions are tail recursive. It gets compiled down to be GOTOs and you won't get a stack overflow (like you will with deep recursion in most languages).

There are other great functional language too, Clojure is great and it's on the JVM. F# is on .NET and is similar to Haskell. The metalanguage (ML) family of languages are cool too but getting old.

Rust takes pretty heavy inspiration from the ML languages and Haskell. It's a great choice if you want to have a greater degree of control than Haskell over memory (functional languages generally use more memory), while still using some of the great abstractions Haskell has like typeclasses (Rust's Traits), and Rust has iterators/closures for writing in a functionalish style at times. Rust is great for large systems and for making games.

If you want to go into machine learning stuff basically your only choice is Python. There are ways to make Python a not totally awful language to use though. Basically my Python style has become pretty reliant on dataclasses and protocols and interfaces and trying to avoid OOP like the plague.

If you go the ML route, there are a bunch of directions that can go. Numpy and Pandas are pretty mandatory to learn. I mostly do NLP stuff, where I frequently use modules like Spacy, Gensim and NLTK. For "Deep Learning" Tensorflow is great (Keras is a great place to start), I don't have much experience with Pytorch. Scikit-learn has a lot of your basic ML stuff that is very valuable to have in your daily toolbox.

Oh and uh I guess if you want to make websites or some frontend shit you can subject yourself to JavaScript and the constantly changing web frameworks. Idk that sounds like literal hell so I don't do it much.
 
Last edited:
  • Agree
  • Like
Reactions: Marvin and Retink
Read in plain english, the definition is "the first two numbers of the Fibonacci sequence are 0 and 1. Every other number in the Fibonacci sequence is the sum of the precious two". It's comically simple.
Ok, so how does that Fibonacci function work, you're trying to produce a result of 0, 1, 1, 2, 3, 5...

You've set fib 0 as 0 and fib 1 as 1, then n is defined as two functions. Let's try fib 2 which would give you fib 1 + fib 0 which results in 1, then fib 3 which is fib 2 + fib 1 = 1+1 which is 2, and then fib 4 would be fib 3 + fib 2 = 2+1 = 3, and obviously it continues down the line correctly as the pattern is established.

But what is the advantage from other languages, in terms of if I wrote this is it just going to run until it reaches n to populate the different results or is it doing something else? I know nothing of Haskell so I don't understand why this would equate to hello world.

Rust takes pretty heavy inspiration from the ML languages and Haskell. It's a great choice if you want to have a greater degree of control than Haskell over memory (functional languages generally use more memory), while still using some of the great abstractions Haskell has like typeclasses (Rust's Traits), and Rust has iterators/closures for writing in a functionalish style at times. Rust is great for large systems and for making games.
Would that make Rust sort of the C# to Haskell? I did want to do some minor gaming programing just to be able to test board/card game ideas and from what I saw Unity was the most popular for that which used C# but it's distinct enough that I didn't want to divert my attention as it was very much a side goal.

If you want to go into machine learning stuff basically your only choice is Python. There are ways to make Python a not totally awful language to use though. Basically my Python style has become pretty reliant on dataclasses and protocols and interfaces and trying to avoid OOP like the plague.

If you go the ML route, there are a bunch of directions that can go. Numpy and Pandas are pretty mandatory to learn. I mostly do NLP stuff, where I frequently use modules like Spacy, Gensim and NLTK. For "Deep Learning" Tensorflow is great (Keras is a great place to start), I don't have much experience with Pytorch. Scikit-learn has a lot of your basic ML stuff that is very valuable to have in your daily toolbox.
I've had minimal exposure to Python, what makes it such a good candidate for ML? As for the other information you mentioned, I haven't heard of it before so I'm completely blind there.

Does a lot of it just come down to available libraries and other information created by those in that field?
 
Ok, so how does that Fibonacci function work, you're trying to produce a result of 0, 1, 1, 2, 3, 5...
The function provided above gives you the nth number in the fibonacci sequence. To generate a list, we can leverage a really cool feature of Haskell called "lazy evaluation". Lazy evaluation makes it really easy to build things like infinite lists. Instead of trying to compute the next element of a list forever and never terminating, Haskell instead says "I'll give you the next value when you ask for it, but not until then", allowing you to specify how much of the infinite list you want to "take", and not computing past that.

There are two common ways you can make an infinite fibonacci sequence. The first uses the provided function above and scales exponentially in compute time, the second scales linearly.

Code:
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)

-- gets you the first n numbers of fib sequence
nfibs :: Int -> [Integer]
nfibs n = take n (map fib [0..])

-- second way, scales linearly
fib :: Num n => [n]
fib = 0 : nxt
    where nxt = 1 : zipWith (+) fib nxt

fibN :: Num n => Int -> [n]
fibN = flip take fib

Both of these are kind of hard to explain without someone having a bit of prior Haskell knowledge, but if you read the first few chapters of Learn You A Haskell then they will make sense.

But what is the advantage from other languages, in terms of if I wrote this is it just going to run until it reaches n to populate the different results or is it doing something else? I know nothing of Haskell so I don't understand why this would equate to hello world.
Sort of going off this but in general terms of advantages Haskell has the huge advantage that other functional languages have, safe concurrency. Race conditions and the like are impossible in Haskell because data in Haskell is immutable, you cannot mutate state. This allows for true parallel processing and very easy and safe concurrent programming. Multithreading in C++ or Python or really any nonfunctional language is a hassle and extremely prone to bugs. Concurrency is easy and intuitive in Haskell and safe to do.

Domain modelling in languages like Haskell is also much clearer than in OOP langs. This is a good talk on that.
Would that make Rust sort of the C# to Haskell? I did want to do some minor gaming programing just to be able to test board/card game ideas and from what I saw Unity was the most popular for that which used C# but it's distinct enough that I didn't want to divert my attention as it was very much a side goal.
No. Rust is more like C but better. Rust's main feature is its borrow checker which makes the language memory safe without using a garbage collector (for the most part, there are unholy texts that explore unsafe Rust.)

I've had minimal exposure to Python, what makes it such a good candidate for ML? As for the other information you mentioned, I haven't heard of it before so I'm completely blind there.

Does a lot of it just come down to available libraries and other information created by those in that field?
Absolutely nothing about the language itself makes it a good candidate for ML. Python kind of fucking sucks as a language. You're right in noticing that it comes down to available libraries.

Python itself is a stupidly slow language, but most Python libraries that do intense computing like Numpy have C internals for doing computation. The libraries available in Python for a lot of ML tasks are now best in class. NLP used to be in the JVM world for a while but that's changed. Python is a shitty toolbox with a lot of excellent tools.
 
Last edited:
The function provided above gives you the nth number in the fibonacci sequence. To generate a list, we can leverage a really cool feature of Haskell called "lazy evaluation". Lazy evaluation makes it really easy to build things like infinite lists. Instead of trying to compute the next element of a list forever and never terminating, Haskell instead says "I'll give you the next value when you ask for it, but not until then", allowing you to specify how much of the infinite list you want to "take", and not computing past that.
Though why is that better than doing a set of for loops? Maybe I'm just applying it to Fibonacci in this case but I feel like I could figure out a loop that can make the same result without generating a list. I should also mention now that when it comes to coding you should essentially view me as a very smart golden retriever at best when it comes to knowledge on the topic.

I'll check out the resources you linked as this is very helpful but in the meantime I do have the following:

Both of these are kind of hard to explain without someone having a bit of prior Haskell knowledge, but if you read the first few chapters of Learn You A Haskell then they will make sense.
Ok, so I do think the readability is nice, if I had to guess without knowledge of the language I think the following is as such:

your first statement sets the conditions of fib 0, fib 1, and fib n.

your get first n numbers sets nfibs to an integer value and then creates an array for all number in the sequence up to and including n with integer value. fibonacci obviously includes no non integer values.

The second statement that scales linearly is gibberish but looks like it's an i++ type of statement that starts at fib 0 and grows to n by incrementing by 1.

If I'm right on this I will say Haskell is way more readable to me than C++.

Absolutely nothing about the language itself makes it a good candidate for ML. Python kind of fucking sucks as a language. You're right in noticing that it comes down to available libraries.

Python itself is a stupidly slow language, but most Python libraries that do intense computing like Numpy have C internals for doing computation. The libraries available in Python for a lot of ML tasks are now best in class. NLP used to be in the JVM world for a while but that's changed. Python is a shitty toolbox with a lot of excellent tools.
That does make sense, though I'm not really planning to be in the career of ML or AI, it's more of a hobby so I don't mind reinventing the wheel and it may probably be helpful to the learning process. I'd rather learn a versatile language and use it to get a much better grasp of coding than my current "I can fumble enough to get something really rough out but it will suck" state, and then apply it to hobbies like those, than learn a language specific to those and struggle with other tasks.

The biggest thing is flexibility as there's not specific goal, just the desire to pick up something that can be used commonly. Essentially I want to pick up the English of coding so that even if I'm the weird foreigner I can still get by in many situations.
 
unless i'm mistaken, you just define individual permissions as bit fields/flags , then you can define specific user permissions by ORing them together. from there, individual permissions can be checked as a boolean using AND.

e.g.
C++:
// 00000001 shifted left 0, so 00000001
#define PERM_A (1<<0)
// 00000001 shifted left 1, so 00000010
#define PERM_B (1<<1)
//etc.
#define PERM_C (1<<2)

// imagine user->perms is an 8-bit integer type with the bit representation 00000000

user->perms = PERM_A | PERM_C; // user->perms is now 00000101

ASSERT(user->perms & PERM_A); // succeeds
ASSERT(user->perms & PERM_C); // succeeds
ASSERT(user->perms & PERM_B); // fails
translated to trannylang, you should then just be able to check for individual flags wherever you checked for a hierarchical status (i.e. mod/admin/etc.) before (instead of checking for some is_mod value, check for the required perms).
>using macros instead of an enum
ISHYGDDT
 
  • DRINK!
Reactions: Knight of the Rope
Though why is that better than doing a set of for loops? Maybe I'm just applying it to Fibonacci in this case but I feel like I could figure out a loop that can make the same result without generating a list. I should also mention now that when it comes to coding you should essentially view me as a very smart golden retriever at best when it comes to knowledge on the topic.
Using it on Fibonacci numbers is just a teaching tool since it's easy to understand, but yeah iteratively or recursively it's about the same either way.

But you could look at Project Euler's problem 18 for an example of a problem where the code for solving it iteratively is an ugly nightmare while the code for solving it recursively is not.
 
  • Agree
Reactions: Anstiv
Sort of going off this but in general terms of advantages Haskell has the huge advantage that other functional languages have, safe concurrency. Race conditions and the like are impossible in Haskell because data in Haskell is immutable, you cannot mutate state.
So I can't do networking, access the disk, print to out to stdout, draw something on the screen, etc.?
What a great language.
 
So I can't do networking, access the disk, print to out to stdout, draw something on the screen, etc.?
What a great language.
I've built web servers and 2d and 3d games in Haskell. Not sure why people think it's impossible when it's extremely easy. I get not everyone understands monads but you don't have to understand monads to have IO. The only practical restriction Haskell sets on IO is that it makes clear when you are handling IO, which is a good idea. You can't open a filestream in every single function and this apparently is baffling to C or Java programmers who think it's an amazing idea to have every single function write to a file as a log and introduce race conditions everywhere.
 
I've built web servers and 2d and 3d games in Haskell. Not sure why people think it's impossible when it's extremely easy.
It was a joke, mate.
If you built a web server, you built something with side-effects. Sending and receiving bytes from another computer (i.e. a mutable global state) is a side-effect. Monads are just a way to let you treat those things in an FP way but they're not making them magically go away.
 
Back