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
Not sure if this has been answered but, in layman’s terms what is the difference between functional programming and object oriented programming?

Additionally, according to google’s lisp style guide they say to avoid modifying local variables and rebind them instead. Why and how do you rebind variables in lisp? Because I’m used to C-style languages so this is all new to me.
 
Not sure if this has been answered but, in layman’s terms what is the difference between functional programming and object oriented programming?
Functional programming: everything is structured in terms of taking the output of one function and feeding it into another in some way. You model your program as a bunch of functions converting input to output.
OOP: you model your program as a bunch of "objects" that interact with each other. Basically any data in your program (read: values of variables etc.) must be represented as an "object" which basically is a blueprint for what values stick together and kosher ways of changing them.
 
Not sure if this has been answered but, in layman’s terms what is the difference between functional programming and object oriented programming?
Two different kinds of retarded.

Object Oriented means that the language is oriented around objects, an object being an encapsulation of data & behavior. Object Oriented is traditionally but not always imperative, meaning you tell the machine what to do in order.

Functional programming means the language is oriented around functions, specifically higher order functions, meaning functions that take functions as parameters. Think map, reduce, filter. Functional programming is usually, but not always NOT imperative, but rather functional (tautology I know); this usually means no looping - you usually just invoke the program with some parameters and it gives you some outputs based on your inputs.

I say usually with both of these because all turing-complete computation is equivalent; and it's all a matter of what suits the problem domain best, and of personal preference.

Javascript, a normally imperative language, can be written in a totally functional style. Elixir, a functional language, reads and writes more like an imperative one.

Furthermore, object-oriented and functional are not mutually exclusive - you can write functions that operate over objects and mutate (change) them - speaking of mutation, that's one thing that functional languages tend to de-emphasize - functional programs tend not to be stateful, meaning that they tend not to store data while running, but the way data moves through the program is as the input/output of functions. Immutability solves a whole host of problems with mutable state, but it's also not a silver bullet either.
 
Additionally, according to google’s lisp style guide they say to avoid modifying local variables and rebind them instead. Why and how do you rebind variables in lisp? Because I’m used to C-style languages so this is all new to me.
I don't know (or care that much) about Lisp. What you are describing here sound to me like preferring immutability.

I found this doing a web search that has a reasonable explanation of why it is often preferred.
 
Not sure if this has been answered but, in layman’s terms what is the difference between functional programming and object oriented programming?

Additionally, according to google’s lisp style guide they say to avoid modifying local variables and rebind them instead. Why and how do you rebind variables in lisp? Because I’m used to C-style languages so this is all new to me.
rebinding variable means declaring variable with the same name. For example if you had variable x and you wanted to change it's value to 20 from 10 you would write
Code:
(defvar x 20)

(let ((x 10))
  (format t "~D~%" x))
 
(format t "~D~%" x)
As opposed to
Code:
(defvar x 20)

(setq x 10)

(format t "~D~%" x)
There is nothing in LISP that stops you from modifying variables; however, if you need some temporary variable, it is better to rebind it so that if you later reuse its name somewhere else, you will not discover that its value is different from what you have expected because it has been modified by code that you have written previously.
 
WolfSSL: Why C Remains the Gold Standard for Cryptographic Software (and not Rust)

Some highlights:

Executive Summary​

For production cryptographic software, memory safety alone does not define security. Real-world crypto must run on every platform, maintain stable assumptions over decades, and allow explicit control over hardware behavior. While memory-safe languages like Rust offer real benefits, serious cryptographic implementations inevitably rely on unsafe code, assembly, and low-level control, eroding those guarantees. At that point, the added abstraction often increases complexity without meaningfully reducing risk. For mature, heavily validated crypto libraries, process, testing, and time-in-field matter far more than the implementation language.

Unsafe Is Inevitable

High-performance cryptography requires:
  • Precise memory layout
  • Predictable calling conventions
  • Tight control over inlining and execution
  • Direct use of assembly
Rust can support this—but only through extensive use of unsafe, inline assembly, volatile operations, and compiler fences. Once a crypto codebase reaches that point, it has largely opted out of the language’s safety model.

This is visible in today’s strongest Rust crypto libraries: they rely heavily on assembly and unsafe, recreating C-like semantics behind additional abstraction layers.

Memory Safety ? Security

Memory-safe languages eliminate certain bug classes—but they do not guarantee:
  • Correct specifications
  • Correct error handling
  • Correct API usage
  • Absence of vulnerabilities
Even in memory-safe languages, logic errors and exception-handling mistakes remain common. Features like unwrap() don’t cause memory corruption, but they can introduce panics or denial-of-service paths in security-critical code.

No language replaces discipline, review, and testing.
 
Been wanting to shift careers and get into real time graphics, so I started working on programming a 3D renderer with OpenGL again. Worked my way through all of the advanced sections of LearnOpenGL, and realized I have not been abstracting things as well as I should. I've been trying to research some design docs for class hierarchy in a 3D renderer, but I can't find anything useful. Specifically for creating a Material class to define how an object is supposed to be rendered, for things like deferred shading and blending.

Anybody have any recommendations for books or docs I could follow for this?
 
Been wanting to shift careers and get into real time graphics, so I started working on programming a 3D renderer with OpenGL again. Worked my way through all of the advanced sections of LearnOpenGL, and realized I have not been abstracting things as well as I should. I've been trying to research some design docs for class hierarchy in a 3D renderer, but I can't find anything useful. Specifically for creating a Material class to define how an object is supposed to be rendered, for things like deferred shading and blending.

Anybody have any recommendations for books or docs I could follow for this?
"Design docs", "abstracting", "class hierarchy"...

In my honest opinion, this is the wrong approach to learning graphics. Those things have absolutely nothing to do with it. It's far better to first learn how to get graphics rendered on the screen without using any frameworks.

Often in imperative programming, the natural and intuitive way to "do" something IS the "right" way. What does it mean to "render"? You're literally just adjusting the RGB values in a 2D array for each pixel that gets displayed on screen. An "object" is simply math you're applying to certain pixels based on the state of the game at each "frame" (next loop cycle). From there, the natural "Abstractions" emerge, for example, it makes sense to store persistent data for an "object" in one place, usually a struct. The conceptualization and Abstraction layer is useful, of course, but it's not essential. Know the process first- the maths.

Abstractions are useful when you properly and fully understand all the groundwork. Starting with OpenGL robs you of learning that groundwork.

It doesn't mean you can't learn OpenGL some day, but just know you will be able to use it so much better once you understand what it's actually doing under the hood.

I recommend watching the Handmade Hero series by Casey Muratori where he builds a video game from scratch. Toward the later days he gets into some pretty sophisticated graphical concepts such as ray tracing etc.
 
if anyone here uses pascal/delphi can you explain the ecosystem to me? why is one of the main public libraries eg jcl seemily partially hidden behind a paywall?
 
Unpopular opinion, but claude opus 4.7 (AI) is unironically great. A lot of times there are tedious things you have to finish and claude can just implement that for you in an instant. It looks at the existing code and writes the code in the same style as the existing code (as all programmers should do), so the code it generates ends up looking like the code you would write anyways.
There are things it cant do, such as things that are not really documented on the internet that require testing and trial, specifically in relation to hardware/proprietary drivers (nvidia). But for those tedious tasks of implementing things that you know how to do but require boring work, just leave it to claude code monkey.
Anecdote time then! I've used Claudio:tm: twice this past week for quite different purposes and gotten very different outcomes. Two scenarios; here's a summary. Brevity is the soul of wit and I'm a fucking moron, so sit down because this "summary" is a long read: Actually, fuck any pretense of "summary". Welcome to my TED talk.

-----------

Due to $work_reasons this week I've gotten more acquainted with GDB than I had hoped to for my entire life. Not entirely unpleasant, but as you might imagine it's a domain where the ratio of "heavy wizardry" to "mostly sane if not necessarily easy" concepts skews way higher than for many other domains. My brain is about ready to bungee off a bridge -- with a skip-rope.

Anyway, I'm soldiering along and making decent progress. But I'm having to learn a LOT of new stuff. And every now and then, after I've understood how to do something, I'd ask Claude (Opus 4.7) whatever it was that I was trying to do, writing my prompts as I would've before learning how to do it. Just a cute little experiment. I gave it really high quality prompts too, sort of try to "spoonfeed" it the stuff I wanted it to do.

100% failure rate. It didn't get a single answer right on the first prompt, and it blithely hallucinated commands that do not exist. When I called it out on it, the tool acknowledged its mistake[1], but on the 2nd round of interaction things weren't much better. Would it have improved if I kept prompting it? Maybe -- but I'm extremely biased agasint """AI""" and had 0 fucking interest in wasting time on it, and this was a for-curiosity's-sake experiment anyway, so I just left it there.

------------

Completely switching context fast enough to give you whiplash (as is the lot of support engineers), I'm now working on a customer question that goes something like this. Hey, I'm using your software and I want to do xyz, but with so-and-so constraints that preclude doing it in what would otherwise be the "usual way". Do you know of something that would do the trick while fitting those constraints?.

To cut the irrelevant bits, the problem boiled down to pulling some information out of a configuration file. "Is entity so-and-so in a specific set", essentially. The kicker is that the config file is

a) written in its own cute custom format (so no generic tools such as `jq` to parse it), and
b) querying xyz would involve not only parsing but also doing application-specific post-processing to actually calculate set such-and-such.

So cobbling together a shell snippet is out of the question. Our software is of course fully capable of parsing and processing its own config files, but we don't have an interface for what the user wanted to do[2]. As I prepare to write the tool that would do what he wants, I again get the cute impulse to try prompting Claudio to do it, see what happens.

Our software is a sizable C codebase. The program I want is essentially `main -> parse_config() -> for entity in config_t->such_and_such_set -> if entity.name==so-and-so -> return 1`, compiled against `liboursoftware.so` to leverage `parse_config` and a bunch of other stuff .

Claudio... got it right. Not just the code; in its reasoning it included a bunch of very insightful remarks that are entirely specific to our project. High-level stuff like

look, the program I gave you DOES what you're asking, but note that membership in such-and-such set can ALSO be altered dynamically at runtime, so *are you sure that what you're asking is a good idea in the first place*, and
The relevant entities defined in the config file can be tagged with an obscure attribute -- it's rare, but it's *possible* -- that, for all normal usages of your software, makes them essentially irrelevant *even if they are defined and in the set*. Maybe you want the ability to filter entities out based on that attribute?

I was impressed. So much so that I went one step further: after it'd given me a perfectly-plausible[3] C program, I looked again at the program description I wanted, and thought, we're essentially calling two/three functions from our `liboursoftware.so` and doing very basic C data-structure walking... this doesn't NEED to be C. Would it be possible to YOLO this shit in Python with a bunch of C interop?.

Now, I know that Python has some degree of C interop, but I've never worked with it first-hand. I'm an engineer worth my fucking salt so I know what underlying mechanisms are going to be in play if this can be done at all, but I have essentially no fucking clue what specific Python facilities are available. I didn't even try to find out: this is the exact prompt I wrote:

Code:
(after Claude produces the PoC in C)

❯ Looks good. I'm curious though -- genuinely, I have no idea if the following
  is workable:                                                                
                                                                               
  This program you've written -- would it be possible to write a version of it
  in Python? Assume [oursoftware] is built and installed, and that the [oursoftware] shared    
  libraries you're using (liboursoftware.so, [...], whatever you need) are
  available.                                                                  
                                                                               
  The biggest hurdle would be the Python - C interop, I suppose. What options  
  do we have here?

And the output looks good. Again, not just the code, but the reasoning, it's hitting all the right concepts. Haven't had the time to go over it with a fine-combed tooth -- plenty of low-level stuff and the devil is very much in the details here -- but on this one, color me fucking impressed.

----------

1777537946909.png

---------

[1]Then again, I don't know if it's because it went over the problem again, or if it's just being expected to say "ah, you're right, my bad" when told "you're fucking hallucinating m8".
[2]Because frankly no-one has ever wanted to do such thing, and I have severe reservations about what's going on in that user's head, but anyway.
[3]Haven't tried it *yet*, but it genuinely looks good on review.
 
I just typed this out for a pinky exercise. You guys try it and time yourself / count the typos:

[...]
Quite the fucking workout. Used backspace when worth it but otherwise went for speed. Did roughly the first half alternating between looking at the source and at what I was writing, the second half I pretty much kept my eyes on the source and prayed.

Spanish layout full keyboard. Most symbols in this layout are AltGr + right pinky so fuck my right hand.

Code:
me@batou:~/shit$ time vim challenge

real    7m20.429s
user    0m0.335s
sys    0m0.038s
me@batou:~/shit$ diff orig challenge 
7c7
< print("start:", x, y, z(3,4))
---
> print("start:" x, y, z(3,4))
39c39
< print("error:", e)
---
> print("error: e,)
47,48c47,48
< data = {"ops":"[]{}();:'\"\\|/<>?"}
< seq = list(range(10))[1:8:2]
---
> data = {"ops":"[]{}();:'\"\\"/<>?"}
> dseq = LIST(RANGE(10))[1:8:2]
52c52
< anyv = any([False, False, True])
---
> anyv = any([False False, True])
55,58c55,57
< pipe = "a|b|c|d".split("|")
< chain = (1+2-3)*4/5
< angle = (a<b) ? a : b if False else c
< print("end:", s, t, u, v)
---
> pipe = "a|b¢cðd".split("|")
> chain = (1+2-c)*4/5
> angle = (a<b) ? a:b if False else c
 
Quite the fucking workout. Used backspace when worth it but otherwise went for speed. Did roughly the first half alternating between looking at the source and at what I was writing, the second half I pretty much kept my eyes on the source and prayed.

Spanish layout full keyboard. Most symbols in this layout are AltGr + right pinky so fuck my right hand.
Nice! I took 13 minutes today. But I did like 5 sets of pullups to failure earlier and have been typing for hours. My pinky just totally crapped out midway through and I kinda took breaks and just froze in place. I think if this workout were like half the length it would be good lol. What throws me off is that 0-= is staggered apart with []\. My pinky is short so i have to move my hand to reach 0, which throws off the placement enough that -, =, [, and ] are seemingly floating off in la-la land. I'm trying to gain "confidence" in the right pinky strikes. It's the hesitation right now that's causing the strain I think. especially between [ and ]. If I could just move my fingers freely like the rest of them I'd be fine.
 
Claudio... got it right. Not just the code; in its reasoning it included a bunch of very insightful remarks that are entirely specific to our project. High-level stuff like
It seems to work better when you prompt it on a codebase instead of general prompts (which are short with no specialized context). Like the codebase itself becomes high quality context for the prompt, so its pattern recognition ends up working better.
I had an issue with gtk once and it wasn't able to solve it, so I just asked it to look at the gtk source code so it downloaded that and went through it and found the issue.
 
I've been reopening some of my old programs as of late on a new PC on Windows 11 and I noticed a weird behavior with SQL Server where if the RAM saturates above a certain threshold (93% more or less in my case), SQL Server just hangs indefinitely on a query, as if it was waiting for something to be allocated. And I mean it hangs in the sense that even doing SELECT 1 seems to run forever, until the RAM drops below the threshold, where it completes instantly as if nothing even happened. Has anyone experienced a similar issue?

I know, the OS of choice is utter garbage, but that's not up to me
 
I've been reopening some of my old programs as of late on a new PC on Windows 11 and I noticed a weird behavior with SQL Server where if the RAM saturates above a certain threshold (93% more or less in my case), SQL Server just hangs indefinitely on a query, as if it was waiting for something to be allocated. And I mean it hangs in the sense that even doing SELECT 1 seems to run forever, until the RAM drops below the threshold, where it completes instantly as if nothing even happened. Has anyone experienced a similar issue?

I know, the OS of choice is utter garbage, but that's not up to me
Is there some other query running in the background maybe? Or indexing?
 
Back
Top Bottom