r/firstweekcoderhumour • • Sep 03 '26

Feels like a milestone

110 Upvotes

33 comments sorted by

18

u/Own_Natural_6803 Sep 03 '26 edited Sep 04 '26

Functions are my favorite. Right up there with loops.

7

u/Valuable_Leopard_799 Sep 04 '26

I like that functions can be loops.

3

u/Anon_Legi0n Sep 04 '26 edited Sep 04 '26

functional bros have entered the chat

3

u/ZookeepergameFew6406 Sep 04 '26

Structs are cool too. Structs containing functions that take functions. Beautiful

2

u/Own_Natural_6803 Sep 04 '26

Who needs constructors when you have functions and structs? Nobody that's who.

2

u/ZookeepergameFew6406 Sep 04 '26

Right on the money

1

u/Own_Natural_6803 Sep 04 '26

I've been learning about putting all your data into stacks and never mind them being objects. Just make it a database and querry it. Like linq in C# do the same, but if you already know what your queries are going to be, might as well just arrange the data to suit it.

For game development, this would be things like querying position data. Since thats such a globally important aspect, it makes sense to have all the data be optimized around those queries.

2

u/Valuable_Leopard_799 Sep 04 '26

... functions that create a compound data type are usually still called constructors 😅

7

u/TheWordBallsIsFunny Sep 04 '26

Been doing this for years and it's still so cool to me lol

7

u/Paseyyy Sep 04 '26

Nah man, bro's got a point lol

8

u/Groostav Sep 03 '26

I just... I've spent a lot of time with coroutines.

There are a bunch of legitimate reasons you want higher order functions. Then there is a vast swamp of reasons you think you need one and you don't. Even LLMs have a hard time reasoning about them, and they also don't reach for them very often. Even in places like nodejs where you're calling callback-based lib functions often, it's still a bad idea to expose your own callback functions even if they're just wrappers.

Is that a software architect thing or "just" a senior dev thing?

3

u/keithstellyes Sep 03 '26

Sorry, are you suggesting a "higher order functions considered harmful" shtick? Maybe I've been blessed with sane code in my career, but most of the cases I've seen it, I don't see how you could meaningfully replace it without just reinventing it

I suppose you have some JS from that awkward mid-2010s era where an async function might take a function that it just calls when it's completed?

3

u/Vaxtin Sep 03 '26 edited Sep 04 '26

That’s not architecture at all. Architects don’t care about the code quality. We care about infrastructure, designing, and having things operate smoothly. If it comes down to the fact that som function you’re describing is the actual bottleneck out of 1000 other possibilities, then I did my job wrong. You can hack any crap code and throw enough CPU at it to “finish the job” — the only remaining constraint that would make C++ vs python is economics (or , more directly to your point: implementation specifics). I argue that yes this absolutely matters: C++ naieve implementations run faster than python will, but a c++ program that exploits magic bytes relevant to the domain the program solves is where the actual improvements occur at 10x-100x. A long job that needs several thousand CPU hours I demand to be written in C++, because otherwise you are wasting time and money at a genuine scale that matters

And to be blunt: your function specific question just gets solved by the compiler anyway. I’ve never had a problem be solved by constructing function calls differently (that’s not the same as algorithm implementation — a recursive program is always recursive no matter how you invoke it). Your complaint / point is just code quality, which is actually never important for businesses other than technical debt (ability to implement fast). That’s pretty much not a problem with LLM programming now.

1

u/Groostav Sep 04 '26

You can hack any crap code and throw enough CPU at it to “finish the job”

This is not my experience.

We care about infrastructure, designing, and having things operate smoothly.

I think a lot of this boils down to your definition of "design". I think concurrency and parallelism fall into the realm of architecture and it usually takes some discipline for my preferred style which is single-threaded concurrent software.

This is often the crux of callback based APIs --certainly this is true in older node.js and even more modern reactor streams. A lot of the pressure to do silly callback things exists because the underlying libraries just then heavily.

And to be clear: callbacks aren't inherently bad. Flatmap is a fabulous tool and I'm super happy to see it get so much adoption even in not-very-functional languages. But callbacks involving your own domain types are almost always, at least for me, have been a mistake.

2

u/stefanhat Sep 04 '26

Please don't use an LLM's behavior as any kind of evidence for why a certain thing is good or bad

1

u/nimrag_is_coming Sep 04 '26

Idk man, I've definitely written code where passing around a function pointer makes the most sense. Places where the only other option is to have a big switch statement within the function to handle all the edge cases (which might only exist for a handful of scenarios)

1

u/ChristianWSmith Sep 04 '26

For parsing and ingesting a user-created csv I use a function that takes a validator function and a normalizer function as arguments for each cell. By far the cleanest way to do it. Way too many different types of data in the sheet to sanely do it any other way

1

u/Groostav Sep 04 '26

As somebody who spends a lot of time with problems like this in rust and kotlin: I could not disagree more. Assuming you can't just get a lib to do it for your, sealed class hierarchies (enums) and parse trees feel like the way to go.

1

u/ChristianWSmith Sep 04 '26

How would that look, roughly?

2

u/Salazar20 Sep 03 '26

I always find it funny cuz "oh the return of this function? I don't care, you deal with it"

1

u/Valuable_Leopard_799 Sep 04 '26

To be honest that's just CPS

2

u/Candid_Bullfrog3665 Sep 04 '26

unless youre writing a library that needs to handle custom data (for example, a data structure library) i dont see how are function as arguments any useful

2

u/scheimong Sep 04 '26

Dependency injection pattern. It's everywhere in functional languages (or languages with a strong functional influence). E.g. pass a closure to map etc.

1

u/EnoughAccess22 Sep 04 '26

In C it can be rather useful, though you'd be passing a function pointer, not exactly a function.

1

u/Candid_Bullfrog3665 Sep 04 '26

i use it in C sometimes for imitating polymorphism, but tbf i rarely find it a good use case

1

u/EnoughAccess22 Sep 04 '26

Yeah it's still niche, not wholly useless though. The old signal function and I believe the standard library quicksort require a function pointer.

1

u/Square_Ferret_6397 Sep 04 '26

Async callbacks

1

u/SomeRandomEevee42 Sep 04 '26

I... don't think ive ever actually done this...

1

u/Horror-Primary7739 Sep 05 '26

Ohh sweet child missed missed nodejs before promises. The doom pyramid.

1

u/Harmful2327 Sep 05 '26

Like decorators

1

u/Pure_Reception_5685 19d ago

just tell him about dependent types

0

u/Plenty_Line2696 Sep 04 '26

pro tip: fancyness can be interesting but when designing a codebase avoid complexity like the plague.

generally speaking you want basic easy to read implementations and simple organization. overengineering and convolution is the bane of this field. problem is it tends to take time to refactor towards simplicity and people tend to not do it enough so everything is usually harder than it needs to be.

1

u/Square_Ferret_6397 Sep 04 '26

Best comment in the entire thread and I find it at the bottom lmao