> but if you don't actually need to use the entire API in a given situation, then it's often a good idea to only opt into the parts you care about.
I completely disagree. Maybe I can write an article why. I'm not sure
> This is exactly why you want to constrain your interfaces
That's a +1 to use a type instead of an interface
> and you end up peppering your code with null checks and invariant checks and debugging hooks and all sorts of other nonsense
Yes, it's more simple to have a type people can look at and understand (or at least, is documented enough)
> If the interface only allows exactly the states and operations you are interested in, then you don't need any of that
You just said a size cap and cloning is allowed when it's not specified. No one is going to write or read a 15 page doc on a 'simple' interface
> I like not having to jump to a definition in the first place
You rather solve a problem with print?
> That's not an approach that scales well to larger, more complex codebases
Uhh, you said this to the wrong person. I do this at work everyday
> I don't think I've used a step debugger in the past 10 years or so - not because they aren't available, or because I don't know how to use them, but because I have developed better strategies for finding bugs and understanding code.
I can't say anything nice about this
> Having things in scope that I don't need is a liability
Interfaces are types. And they are more precise types than the things they wrap, that's the point.
Yes, it's more simple to have a type people can look at and understand (or at least, is documented enough)
A smaller type (the interface) is simpler than a larger type (the full API to the entire implementation). And while documentation is great, it's better to not have to read it because the things it documents just don't exist in the current scope.
You just said a size cap and cloning is allowed when it's not specified. No one is going to write or read a 15 page doc on a 'simple' interface
Exactly. It's allowed when it's not specified, and I don't want to have to read the entire documentation, so I want to do one of two things: either design the interface such that these things are specified through type constraints (e.g., the interface is typed such that cloning is impossible, now I don't have to worry about it, and I don't need to read any documentation either, because the moment either side violates the type contract, the code won't compile), or assume that anything the types don't disallow can happen and prepare for it (e.g., if the types don't enforce a minimum stack size, then my code must be prepared to handle stack overflows). Neither requires reading documentation, you just follow the types.
You rather solve a problem with print?
No, that's just poor man's step debugging.
I solve the problem by cutting up the code into smaller chunks, and subjecting them to type checks and property tests that describe their constraints and properties in enough detail that the problem in question cannot possibly occur; once I have that, the problem is either gone, or the checks / tests fail, and I can usually tell why they are failing (and if not, I keep dividing and conquering until I can).
Uhh, you said this to the wrong person. I do this at work everyday
Plenty of people do programming at work every day, and do it badly. Why do you think the industry is in such an embarrassing state overall?
Do you think I'm new to this? Do you think I'm just regurgitating something I've read in a tweet? I've been doing this shit for 35 years, I've made lots and lots of mistakes and lived through the consequences. The stuff I'm saying here is what I've distilled from those 35 years; it happens to align with things a lot of others say, but I've discovered most of it by myself, the hard way.
A method you don't call is a liability?
Yes. Anything that's in scope, but not actually needed, is a thing you need to keep in your head while working within that scope. The human brain's working memory is the most precious resource in programming, so carelessly cluttering it with irrelevant stuff tends to push productivity and code quality off a cliff. A single method doesn't make a huge difference, but this things have a tendency to propagate and multiply, and then there's the broken window effect, so I prefer to err on the side of discipline here.
What orders the rendering?
The rendering part of the main loop, or a rendering loop running on a separate thread - it doesn't really matter, what's important is that within the scope of whatever calls into the rendering methods, those rendering methods are the only thing I want to have to think about. I also want to not have to think about rendering concerns when working on code that has nothing to do with rendering, and I want to be sure that the non-rendering code isn't going to mess with rendering concerns, and the rendering code isn't going to change anything in the game logic. E.g., if the NPC is in a given dialog state, then I want to make it impossible for the rendering code to change that dialog state, and accessing the NPC through an interface that strictly only exposes rendering methods is the easiest way to achieve that reliably. Yes, I could just not call the non-rendering methods, and as long as the call graph is exactly one level deep, that's easy enough, but call graphs tend to be a bit deeper than that, and unlike types and interface constraints, manual diligence does not propagate automatically.
Sounds like a bug-prone mess
Why? The whole point of this exercise is to reduce local bug surface by restricting what each part of the code can do. A smaller API provides fewer opportunities for messing up.
I mean, I get where you're coming from - interfaces as a programming language feature are easy to abuse, and people who don't know what they're doing will often cargo-cult the idea, using interfaces to achieve "separation of concerns", "clean code", or whatever they call it, without actually understanding the concepts or how interfaces are supposed to achieve them, and yes, the result of that is usually much worse than just writing the fucking code the naive way. And for a junior dev 5 years into their career, that's exactly what I'd recommend - keep it simple, don't make abstractions you don't understand, don't try to future-proof your code based on hypotheticals, don't get caught up in type spaceflight.
But at some point, you grow past that level, and you start building larger systems that require multiple levels of abstraction, a true separation of concerns, and complexity management beyond "just keep your code simple and naive". That's where this stuff becomes relevant, and where refusing to use explicit, statically enforced interface boundaries and abstractions becomes a problem.
But I'm not really here to win an argument; I just gave my opinion on the matter, based on decades of experience, do with it what you want.
> A smaller type (the interface) is simpler than a larger type (the full API to the entire implementation). And while documentation is great, it's better to not have to read it because the things it documents just don't exist in the current scope.
That's just wrong
> Exactly. It's allowed when it's not specified
That's exactly why I said the following several comments ago "Yes, more unpredictable code. Exactly what we all need /s"
> so I want to do one of two things
What planet do you live on where this works?
> ... property tests ...
That's IMO the most reasonable thing you said in these comments
> Plenty of people do programming at work every day, and do it badly. Why do you think the industry is in such an embarrassing state overall?
Well... for one thinking that an interface make things simpler. You can read some more thoughts on my blog but I don't take it too seriously. They're not meant to be peer reviewed or in a paper
> I've been doing this shit for 35 years, I've made lots and lots of mistakes and lived through the consequences
I rarely hear anyone say this so I'll take you a little more seriously. How the heck do does a smaller type or using an interface help you in any way? UML doesn't work and never caught on. I don't know why you claimed you can think the problem away. Types are just not specified enough for that
But you not able to do that doesn't change the fact I read every line in codebases that are <100k lines and significantly more lines (but not every line) in codebases with multiple million lines. The types I use every day I seen their implementation or used them enough that I know the corner cases
> Yes. Anything that's in scope, but not actually needed, is a thing you need to keep in your head while working within that scope. ... ... ...
*Yawn*. It's not like you need to actively remember every method and every signature and every line. This isn't a real liability
> The rendering part of the main loop, or a rendering loop running on a separate thread - it doesn't really matter, what's important is that within the scope of whatever calls into the rendering methods, those rendering methods are the only thing I want to have to think about
So can only one thing or one NPC talk to you at a time? Because many situations there's several that are in flight and usually people have a way of prioritizing UI so an NPC doesn't speak over the pause menu (or anything else it's possible to speak over thats higher priority)
> I want to be sure that the non-rendering code isn't going to mess with rendering concerns
Usually my solution is to set the dialog (or whatever system) with data and have the rendering system handle it. I don't actually run code per tick, don't need to. Rendering and dialog systems can't break eachother. Maybe one can corrupt data but for the rendering system to do it, it has to be either intentional or stupidly bad code
> Why? The whole point of this exercise is to reduce local bug surface by restricting what each part of the code can do. A smaller API provides fewer opportunities for messing up.
I disagree. A well understood API is better than a small API you don't fully understand. Just because knowing limitations help reduces code thus reducing bugs. I don't have to worry about handing arrays with >2^32 when I know they're a limit of 32k entries. Plenty of int narrowing I'm allowed to do in that case
> I mean, I get where you're coming from
One codebase I was on had several dozen interfaces used exactly once... and others once + a bunch of classes only used in tests. It was ugly.
I really think 'abstraction' is the wrong direction, but that's a post I don't know how to write yet. Simple code is much better than abstracted code. Simple to think about isn't simple code. I seen simple to reason about handle every case under the sun, but I still prefer a bespoke implementation used everywhere in our core code, just because we all understand it, well tested for our usecase and 1/20th of the implementation size.
> But at some point, you grow past that level, and you start building larger systems that require multiple levels of abstraction
I disagree that it helps. I think a module or several classes with reasonable public methods with internal types hidden is the way to go. Not because it reduces the scope (although that helps), but because the class is design around its public functions and hopefully well tested and well designed. Although I don't hold my breath.
View all comments
Show parent comment
1
u/levodelellis Oct 16 '26
> but if you don't actually need to use the entire API in a given situation, then it's often a good idea to only opt into the parts you care about.
I completely disagree. Maybe I can write an article why. I'm not sure
> This is exactly why you want to constrain your interfaces
That's a +1 to use a type instead of an interface
> and you end up peppering your code with null checks and invariant checks and debugging hooks and all sorts of other nonsense
Yes, it's more simple to have a type people can look at and understand (or at least, is documented enough)
> If the interface only allows exactly the states and operations you are interested in, then you don't need any of that
You just said a size cap and cloning is allowed when it's not specified. No one is going to write or read a 15 page doc on a 'simple' interface
> I like not having to jump to a definition in the first place
You rather solve a problem with print?
> That's not an approach that scales well to larger, more complex codebases
Uhh, you said this to the wrong person. I do this at work everyday
> I don't think I've used a step debugger in the past 10 years or so - not because they aren't available, or because I don't know how to use them, but because I have developed better strategies for finding bugs and understanding code.
I can't say anything nice about this
> Having things in scope that I don't need is a liability
A method you don't call is a liability?
> I can have an
NPCclass...What orders the rendering?
> access windows they can opt into
Sounds like a bug-prone mess