Programming thread

  • 🔧 Chat is under maintenance.
    🧊 New server is in an office waiting on a mexican.
  • 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
Structs and functions are enough.
I do frequently put function pointers into structs for poor mans objects. But it very much is the exception, as I live by "have 100 functions operate on 1 data structure, rather than 10 functions each for 10 structures"
Making state management easier. Which it does, but avoiding state is even better and lots of OOP stuff encourages you to put state all over the place, resulting in the spaghetti ball on the right. Doesn't help that a lot of OOP languages are also crippled in other ways.
Making state a hidden thing you can treat like a black box. What it lead to was mutable global state that's hidden.
"Let's try MY mental model, surely it will fix everything!" At least GOF did it while high and in Aspen I guess.

Also I like interchangeable parts. Standard bolts are neat.
1794789379806.png
 
I do frequently put function pointers into structs for poor mans objects. But it very much is the exception, as I live by "have 100 functions operate on 1 data structure, rather than 10 functions each for 10 structures"

Making state a hidden thing you can treat like a black box. What it lead to was mutable global state that's hidden.

View attachment 9860018
A big place where interfaces can help with development is when you're trying to pass ABI barriers, What I essentially mean is when writing mods for games, you have to deal with shit where multiple plugins need to handle one specific kind of data structure. And while you can probably make that a generic pointer, it's a bit easier just to have an interface and a header that they all can just import. Yeah, it's still basically a function under the hood, but it makes it prettier.
 
What was the selling point behind OOP, again?
Alan Kay devised a method of programming so simple that children could use it to write massively parallel programs, Object-Orientation, realized through a language named Smalltalk. A Danish idiot named Bjarne Stroustrup made a preprocessor for the C language that bolted a bad imitation of Smalltalk's less important qualities onto it. Now an adult and professional C++ language programmer working on a video game or critical infrastructure struggles to handle a few independent threads of execution, while sporting an insane fetish for efficiency in the small and blindness in the large.
 
Smalltalk.
I've seen a video on Pharo. Literally what is the difference between that and just using my terminal? I feel like half of these things are just "oh my OS's terminal is a deprecated piece of shit that I don't know how to use."

This kind of coincides with "C not having a package manager" roody-poo you have apt, pacman, dpkg, -etc.
 
Making state a hidden thing you can treat like a black box. What it lead to was mutable global state that's hidden.
If your objects encapsulate global state, then your objects are essentially modules and you're not really getting your money's worth out of OOP. That's a user problem though; common user problem maybe, but still.
 
I've seen a video on Pharo.
I try not to use YouTube.
Literally what is the difference between that and just using my terminal?
The idea behind a full Smalltalk environment is the system comprising one language, top-to-bottom to the fullest extent possible. Modern Smalltalk implementations hit bedrock in a virtual machine rather than microcode. I'm much more familiar with Lisp listeners of that era, but does escaping the limitations of emulated video terminals not already sound appealing? It's telling that so much of our best virtualizations are predicated on mimicking what physically existed once, since most software is too pitiful to enforce real standards otherwise.
I feel like half of these things are just "oh my OS's terminal is a deprecated piece of shit that I don't know how to use."
The idea behind a malleable environment is being able to change it as it's used. This is called an image. UNIX is also an image, just an extraordinarily shitty one.
This kind of coincides with "C not having a package manager" roody-poo you have apt, pacman, dpkg, -etc.
That has no bearing on this.

Anyway, one old idea that led to Object-Orientation was the US military sending tapes to other bases, with a convention of using function pointers in standard locations for standard functions. So, a tape could be loaded and enquired about its contents in this way, a neato idea.
 
I do frequently put function pointers into structs for poor mans objects. But it very much is the exception, as I live by "have 100 functions operate on 1 data structure, rather than 10 functions each for 10 structures"

Making state a hidden thing you can treat like a black box. What it lead to was mutable global state that's hidden.

View attachment 9860018

Yeah the first time I listened to a DDP talk I felt like I had come home or sat down for the first time in my life.

"You mean I can just pass data between functions and we can namespace the functions?"

🎶 Leave it to beaver jingle

"OF COURSE YOU CAN, SON!"

>mutable global state that's hidden.

I had a job with some spaghetti code that had 10,000 loc classes with class level properties. But also passing n-1 or n-2 params to a given method. It took forever to memorize what was going on and why we'd instantiate god classes and then have some props class level and others passed and no they weren't even prefixed.

This is why I want explicit "you work on what you pass" shit. POCO sure blah blah blah but my god man, there should be a rule that when you are working on the start of a function or method or WHATEVER, that you should be able to see every thing you need to know in one screen or something. So I came up with one.
 
I'm brand new to programming, but it is normal to not know which object class inherits which other class and which method takes what parameters from where and where they go from first glance? I tried to learn Flask recently and while I got it to work I ended up just rote memorising certain properties and methods since the documentation is terrible.
 
I'm brand new to programming, but it is normal to not know which object class inherits which other class and which method takes what parameters from where and where they go from first glance? I tried to learn Flask recently and while I got it to work I ended up just rote memorising certain properties and methods since the documentation is terrible.

If it's this hard to tell, it likely needs to be refactored; if you're new then the lesson you're about to learn might well be "politics in the workplace." Sometimes the spergs get stupid about things, and sometimes the NT bosses are even stupider. (Much stupider).

The second I had access to an IDE that could keycombo -> PARENT or keycombo2 -> FIND_USAGES, I started abusing the hell out of it.

If you're using a text editor you might need a language server for it to hook into.

Are you at a workplace or solo?
 
I'm brand new to programming, but it is normal to not know which object class inherits which other class and which method takes what parameters from where and where they go from first glance? I tried to learn Flask recently and while I got it to work I ended up just rote memorising certain properties and methods since the documentation is terrible.
tbh you will usually not know how the codebase works unless you have previous experience with it.
 
I'm brand new to programming, but it is normal to not know which object class inherits which other class and which method takes what parameters from where and where they go from first glance? I tried to learn Flask recently and while I got it to work I ended up just rote memorising certain properties and methods since the documentation is terrible.
Flask documentation is pretty decent. If you have a decent editor or a decent editor plugin, it will show you the usage for classes, methods etc.
 
Apropos of recent news, I will add that the 10K LOC classes with spooky class level props had worse things like multiple output params and threading-while-threading, and it was all flight planning/W&B/flight safety stuff

lol lmao

god I hate this fucking industry

All I ever do is fix bullshit
 
I like optional variables in Common Lisp and Ada, so I'm assuming Python fucks it up in some pathetic way. I recall reading that the default values are evaluated once at function definition rather than each time the function's called, for one. The more I learn about programming and Python, the worse the latter looks in every respect, so may I have a link to read more about why it's secretly a good thing the dipshit who made this language refuses to mentor white men?
An example of a language that does this correctly (and has a fair number of features ripped off by Python, but unfortunately not this one) would be Icon, where every argument is optional and defaults to &null, which gets away with this because it has a convenient feature for providing default values. The unary operator /x succeeds if x has the null value and fails if x has a non-null value (the default action if an expression fails is to skip the rest of the statement and continue on to the next one). Furthermore if x is an assignable variable, then /x is also an assignable value. This means that Common Lisp's
Code:
(defun f (&optional (a 5) (b 3) (c (+ a b)))
  ...)
can be written as
Code:
procedure f(a, b, c)
    /a := 5
    /b := 3
    /c := a + b
    ...
end

Since Python doesn't provide this and optional arguments have their default values evaluated at definition-time, you have to do abominations like
Python:
def f(a = 5, b = 3, c = None):
    if c is None: c = a + b
    ...
which becomes really tiresome when you have more than one argument that needs to be treated in this way, since there is absolutely no shorthand for it.
 
An example of a language that does this correctly (and has a fair number of features ripped off by Python, but unfortunately not this one) would be Icon, where every argument is optional and defaults to &null, which gets away with this because it has a convenient feature for providing default values. The unary operator /x succeeds if x has the null value and fails if x has a non-null value (the default action if an expression fails is to skip the rest of the statement and continue on to the next one). Furthermore if x is an assignable variable, then /x is also an assignable value. This means that Common Lisp's
Code:
(defun f (&optional (a 5) (b 3) (c (+ a b)))
  ...)
can be written as
Code:
procedure f(a, b, c)
    /a := 5
    /b := 3
    /c := a + b
    ...
end

Since Python doesn't provide this and optional arguments have their default values evaluated at definition-time, you have to do abominations like
Python:
def f(a = 5, b = 3, c = None):
    if c is None: c = a + b
    ...
which becomes really tiresome when you have more than one argument that needs to be treated in this way, since there is absolutely no shorthand for it.
What usecase would there be for interdependant default args?
 
What usecase would there be for interdependant default args?
Maybe the length or final index of a sequence, which might be useful for something like:
C-like:
// Pseudocode
func removeSpineSlice(spine: Seq[Vertebra], start: Int = 0, end: Int = spine.length) {
    // TODO implement brutal murder
}
 
where every argument is optional and defaults to &null,
That sounds horrifying, even with an easy way to specify defaults. Implicit nullability is another one of those big evils of programming.
What usecase would there be for interdependant default args?
Taking a sequence, a start point, and an end point, where start defaults to 0 and end defaults to the length of the sequence. Generally, anything where there's an argument that can sensibly default to something derived from another argument.
 
What usecase would there be for interdependant default args?
In Icon, the big use case would be pattern matching functions. The pattern is that the last three arguments are the string that is being searched, the index to start searching at, and the index to stop searching at. If a string is provided, the starting index defaults to 1, and if it isn't the string defaults to the contents of &subject and the starting index defaults to the contents of &pos (these are global "keyword" variables with dynamic scope managed by the binary ? pattern-matching operator). In either case, the ending index defaults to the length of the string plus one (the first index past the end of the string).

If you aren't building your function out of the primitive ones provided to you, you'd initialize them like this:
Code:
procedure f(..., s, a, z)
    /a := if / s then &pos else 1
    / s := &subject
    /z := *s + 1
    ...
end
(apologies for the space between the slash and the s, but otherwise it gets wordfiltered to /sneed even within a code block)

If you are building your function out of the primitive ones, you just pass in the potentially-null arguments and let the primitive worry about it:
Code:
# match exactly N characters from cset cs
# usage: exactly(4, &digits)
procedure exactly(N, cs, s, a, z)
    N >= 0 | fail
    while N > 0 do {
        a := any(cs, s, a, z) | fail
        N -:= 1
    }
    return a
end
 
Last edited:
What usecase would there be for interdependant default args?
As others have given a usecase for that, I'll share one even more obscure: Common Lisp provides the ability to see if the parameter was provided a value, which allows one to distinguish between the case of an omitted parameter and a supplied parameter given the default value. I love Common Lisp for thinking of everything like this, but I've only ended up using it once. It looks like this:
Code:
(lambda (&optional (symbol-name default-value supplied-p))
  ...)
This can also be done with the keyword parameters, Common Lisp's version of named arguments, as described here.

One very nice feature of Ada is how all parameters can be used with or without names. This makes parameters' names part of the interface, but that's a small price to pay.
The pattern is that the last three arguments are the string that is being searched, the index to start searching at, and the index to stop searching at.
While cool, I prefer slices for this manner of thing.
(apologies for the space between the slash and the s, but otherwise it gets wordfiltered to /sneed even within a code block)
Use the [plain][/plain] tags for that purpose. That previous sequence was written as [plain][plain][/plain][/plain] for example.
 
Back
Top Bottom