Programming thread

  • Want to keep track of this thread?
    Accounts can bookmark posts, watch threads for updates, and jump back to where you stopped reading.
    Create account
It's just a matter of speed. In Normal mode, you don't have to move your fingers away from the home row on your keyboard to move the cursor around. For up and down, your fingers don't move from the home keys. Moving down is just a quick tap of the index finger.
If it helps, you can use Ctrl-[ instead of ESC to get back to Normal mode. Though swapping ESC and Caps Lock is the best way to go imo. Once you get the hang of it all, it's way faster.
I have a fucked-up idiosyncratic typing method where my left hand does virtually all the work (despite being otherwise right-handed) so this efficiency gain wouldn't apply to me
 
vis which is suckless vim or whatever
apparently has been in active development for at least 11 years now
vis-non-goals.webp
Based. Get rid of Richard (((Stallman)))'s (((Emacs))) extended with (((Lisp))) created by John (((McCarthy)))* and install vis to gas the kikes!

* Actually look into it
 
To move around in vim, you type /word or ?word and then hit n or N repeatedly.
fun fact
in helix /word and ?word are also a thing, and they both work the same, but n always moves forward and N always moves backwards, no matter if it was a forwards or backwards search
 
Are you really even using an editor if you don't have to have a reference guide stuck to your keyboard? (Yes, fine, it's WordPerfect, which really was nearly a perfect word processor.)
ib128e8ydg251.webp
I used to install Joe everywhere, a hold over from knowing WordStar commands. Now for system use I just tolerate whatever flavor of vi is installed and run VS Code/now VSCodium for my actual "work".
 
How do I get 'cracked' at programming

How do I gain the ability to look at a file full of abstract code and libraries I don't use and then go "oh, the author missed a few optimizations here"

How do I learn what is happening in the machine

How do I look at open source projects and easily make meaningful contributions
 
How do I get 'cracked' at programming

How do I gain the ability to look at a file full of abstract code and libraries I don't use and then go "oh, the author missed a few optimizations here"

How do I learn what is happening in the machine

How do I look at open source projects and easily make meaningful contributions
Eat more curry.

But in reality the answer is the same as "How do you get to Carnegie hall." "Practice, practice, practice."

I had the advantage of starting small since that's all there was. Learning to program 6510 assembly gives one a good view of LOW level, then up through C and onward. Some data structure classes and understanding of O() notation was helpful too. There was one OpenSource project I was playing with and increased the number of inputs slightly and made it way slower. Then realized they had managed to implement a simple algorithm as O(n^3)

You have to learn to look at the big picture, why does this code look like that code, why isn't it a shared function, is there a reason. How can I implement this better, can I implement it better.

One thing I've found is that as long as you have a good foundation you can really deal with most languages these days (except possibly outliers like LISP) as JavaScript, C, Python, Perl, Rust, Golang are all pretty readable if you know the basics.
 
How do I get 'cracked' at programming

How do I gain the ability to look at a file full of abstract code and libraries I don't use and then go "oh, the author missed a few optimizations here"

How do I learn what is happening in the machine

How do I look at open source projects and easily make meaningful contributions
Personal projects and books from really smart people.
 
How do I gain the ability to look at a file full of abstract code and libraries I don't use and then go "oh, the author missed a few optimizations here"
I'm not sure there are any shortcuts here. You will have to study and, typically in the process, use the code in question. Are you interested in data structures and algorithms that can help promote more efficient outcomes?
How do I learn what is happening in the machine
There is somewhat more theoretical information on various aspects of this but as far as the actual coding aspect is concerned, it will typically involve C (maybe C++) and various types of assembly language. You'll end up finding out about the theory in the process.
One thing I've found is that as long as you have a good foundation you can really deal with most languages these days (except possibly outliers like LISP) as JavaScript, C, Python, PERL, Rust, Golang are all pretty readable if you know the basics.
Perl can be perfectly readable but I would argue it still goes into the outlier category. I have quite a few other things I don't like about Perl:
(I later learned that my point about number types isn't entirely solid but the rest appears to stand)
 
How do I get 'cracked' at programming
spend at least a few years being heavily autistic about programming (and writing a bunch of programs that do various shit) and you'll be there before you know it
How do I gain the ability to look at a file full of abstract code and libraries I don't use and then go "oh, the author missed a few optimizations here"
you generally have to know what's going on in a program if you want to be able to improve it
to understand libraries you don't use you generally spend some time reading through documentation
if you hate reading 5 different tabs of documentation, programming is definitely not for you

also keep in mind that optimizations are rarely what programmers aim for when modifying a program
the very best programs are always written to be logical and understandable to humans as formal descriptions of symbolic manipulation processes that just so happen to be easily carried out on a machine
it is good if they are fast, but sacrificing clarity for speed is considered a desperate measure generally only taken by core library functions that must run at extreme speeds
ironically, it can be far easier to speed up a nicely written program than it is to speed up a poorly written program that has had its clarity sacrificed for minor speedups
How do I learn what is happening in the machine
if you aren't already using a gnu/linux-based operating system, you should install one in a vm or an old laptop or something. windows has a shitty general philosophy of hiding shit from you, so it's easier to learn stuff like c on a unix-like system
keep in mind that you will never learn absolutely everything, so you'll have to settle with many things just being high-level black boxes (unless you go learn more about how they work)
How do I look at open source projects and easily make meaningful contributions
hack on shit until you have a sense for the aesthetics of a program. then, find something shit about a project that people (you being one of them is a great motivator) want fixed and go fix it
you will have to learn shit like git to actually do the contribution process but that's easy if you are already a linux user
being comfortable in terminals is a hallmark of better-than-average programmers, since good programmers are generally not supposed to be afraid of repls for retarded scripting languages (which is what bash is and how it works)

(except possibly outliers like LISP)
lisp (and even more so scheme) have a strange habit of conveniently brushing against a number of really deep computing concepts, and every programmer should at least take a shot at one of them
they are naturally quite expressive too, and that's even before you use their special features that let you define entirely new language keywords

Are you interested in data structures and algorithms that can help promote more efficient outcomes?
not knowing what you are trying to do in the first place is a grave error when it comes to any art form
this includes programming
Perl can be perfectly readable but I would argue it still goes into the outlier category.
perl may have lots of rough edges and a hard-to-get-into syntax, but it isn't extremely unusual as a programming language
yeah sure the sigils are an abomination and the magic variables are weird but you can get used to all of that fairly quickly

and it can be downright pleasant for mangling text, with its concise syntax for doing shit to strings using regex
its regex support is so downright awesome that most things base their regular expressions on perl
 
How do I get 'cracked' at programming
Practice—it's the only way to get gud.

How do I gain the ability to look at a file full of abstract code and libraries I don't use and then go "oh, the author missed a few optimizations here"
This comes over time with experience. You start recognizing patterns typical of poorly written code and develop an intuitive sense of what looks "right" vs "wrong".


Tangentially related: I recently have been working on adding features to a simple S3 gateway I wrote in Go for my personal sites. I could go on a whole rant about how disgusting and cluttered their official Go SDK libraries are, but I'll keep things concise with a specific example.

While looking through their example code (from here) to get my bearings, something niggerlicious caught my eye:
C-like:
// ListObjects lists the objects in a bucket.
func (basics BucketBasics) ListObjects(ctx context.Context, bucketName string) ([]types.Object, error) {
    var err error
    var output *s3.ListObjectsV2Output
    input := &s3.ListObjectsV2Input{
        Bucket: aws.String(bucketName),
    }
    var objects []types.Object
    objectPaginator := s3.NewListObjectsV2Paginator(basics.S3Client, input)
    for objectPaginator.HasMorePages() {
        output, err = objectPaginator.NextPage(ctx)
        if err != nil {
            var noBucket *types.NoSuchBucket
            if errors.As(err, &noBucket) {
                log.Printf("Bucket %s does not exist.\n", bucketName)
                err = noBucket
            }
            break
        } else {
            objects = append(objects, output.Contents...)
        }
    }
    return objects, err
}
In the for loop, they do this weird shit with their if err != nil statement to make the function return at that last line, regardless of whether any errors took place. In Go, if a returned error value isn't nil, then any results returned along with that error should be discarded. So this function technically follows the rules and will return an error if any took place (due to the break above the else block). However, it uses a lot of (not so) clever control flow trickery to pull off this single return instead of doing something reasonable like:
C-like:
// ListObjects lists the objects in a bucket.
func (basics BucketBasics) ListObjects(ctx context.Context, bucketName string) ([]types.Object, error) {
    var err error
    var output *s3.ListObjectsV2Output
    input := &s3.ListObjectsV2Input{
        Bucket: aws.String(bucketName),
    }
    var objects []types.Object
    objectPaginator := s3.NewListObjectsV2Paginator(basics.S3Client, input)
    for objectPaginator.HasMorePages() {
        output, err = objectPaginator.NextPage(ctx)
        if err != nil {
            var noBucket *types.NoSuchBucket
            if errors.As(err, &noBucket) {
                log.Printf("Bucket %s does not exist.\n", bucketName)
                err = noBucket
            }
            return nil, err
        }  
        objects = append(objects, output.Contents...)
    }
    return objects, nil
}
Using an early return is much cleaner and more explicit. Plus, you get to avoid adding an unnecessary level of indentation from using the else block. tbh I can count on one hand the number of times I have had to use an else in my work.
This is stuff they teach in 1st year CS—be explicit, not clever; avoid using break wherever possible for clarity; etc.—and somehow this passes the smell test for the higher-ups at Amazon. I have seen much worse code over the years, but this is just stanky and screams of a lack of experience.

This old Linus quote has served me well:
Linus said:
if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program.
Some languages make >3 more necessary, but the overarching point of avoiding a shitload of nesting stands.
 
Last edited:
it uses a lot of (not so) clever control flow trickery to pull off this single return
one of the infernal tools it uses to commit this retarded spaghetti logic is mutation
the = operator being a single character in many languages has been a disaster to the human race
setting variables to values in if statements and breaking out of messy loops and if statements to return them in 1 centralized spot is the 21st century equivalent of goto spaghetti
not saying you should never use it, it's just not very useful in this code

the funniest thing about this function is that (afaict) the error check might do a lot of extra looping
if an object that hasmorepages can't find its nextpage but still hasmorepages afterward for some reason, this will loop infinitely
Some languages make >3 more necessary, but the overarching point of avoiding a shitload of nesting stands.
excessive nesting seems to be a problem of overly large functions, but this one seems to be fine. the real problem here is just that whoever wrote this function wasn't thinking (never a good idea in programming) so they used the wrong flow control tools (and a few unnecessary mutations) to make unclear shitcode

one of the neat things about lisp-like languages is that they strongly encourage the use of early returns by basically making it into the default thing
 
one of the infernal tools it uses to commit this retarded spaghetti logic is mutation
the = operator being a single character in many languages has been a disaster to the human race
setting variables to values in if statements and breaking out of messy loops and if statements to return them in 1 centralized spot is the 21st century equivalent of goto spaghetti
not saying you should never use it, it's just not very useful in this code

the funniest thing about this function is that (afaict) the error check might do a lot of extra looping
if an object that hasmorepages can't find its nextpage but still hasmorepages afterward for some reason, this will loop infinitely

excessive nesting seems to be a problem of overly large functions, but this one seems to be fine. the real problem here is just that whoever wrote this function wasn't thinking (never a good idea in programming) so they used the wrong flow control tools (and a few unnecessary mutations) to make unclear shitcode

one of the neat things about lisp-like languages is that they strongly encourage the use of early returns by basically making it into the default thing
Something funny I realized after posting was that the else block still wasn't necessary in their version with the break since control flow would still divert before the append. The fact this wasn't readily obvious to me nor the author speaks to the subpar quality of the code. All "features" of a function should be obvious at a glance.

Edit: an interesting thing to note is that the := shorthand operator will shadow any variables defined in outer blocks. So they have to define variables like the NextPages output outside of the for so that they don't shadow the err var they also have to declare outside to use in the final return. It's really disgusting.
 
Last edited:
if you aren't already using a gnu/linux-based operating system, you should install one in a vm or an old laptop or something. windows has a shitty general philosophy of hiding shit from you, so it's easier to learn stuff like c on a unix-like system
This is how I ended up making the switch to Linux from Windows.
 
Back
Top Bottom