|
|
|
|
|
by chowells
1279 days ago
|
|
Why do you care if a number is greater than 100? That has to actually mean something to you. What does it actually mean? Is it a validation error? Is it a warning trigger? Why not have a data type that actually expresses that meaning? Wait, are you hung up on implementation nonsense? Sure, there's a low-level operation that returns a 0 or 1 that you convert into your actually-meaningful data type. But that doesn't need to have a surface language boolean type that's privileged by the language design. And that's what's important here - language design. People write programs in a language, not compiled code. The model the language provides is of critical importance. It's how the users of the language think and how they communicate with each other. And this isn't abstraction. Boolean is the abstraction. It throws away all but a single bit of information. This is creating data types with semantics that carry far more than that single bit. It's making your code less abstract. |
|
You could make a battle royal game well where people start taking damage when they are 100 units away from the center of the map.
>Why not have a data type that actually expresses that meaning?
It would add unneccessary complexity.
>Wait, are you hung up on implementation nonsense?
The base of what it being abstracted over is not nonsense.
>But that doesn't need to have a surface language boolean type that's privileged by the language design.
If exposing booleans lets people write simpler code then it makes sense to expose it instead of forcing complexity onto everything.
>Boolean is the abstraction.
No, booleans are a concept that the processor understands. Zero is false and nonzero is true. The processor has instructions like like logical and that can operate on these booleans. Branches can happen based off a bit in the status register. A bit has two states which maps to true and false. Booleans are a fundamental concept that is being built upon. The processor has a limited number of data types that it understands. Creating new data types is creating abstractions because those data types do not actually exist. You are simply hiding an actual data type in the new one you are creating.