Email or username:

Password:

Forgot your password?
nixCraft 🐧

perfect function doesn’t exis- πŸ‘‡

80 comments
Fuchsiii~~~

@nixCraft

my Ryzen 7750X:
is_computer_on(); // 1

a cache corrupting i7 14700k:
is_computer_on(); // 153

James πŸŒˆπŸ’œ

@nixCraft Too bad it won't run on DOS, where we really need it!

rl_dane

@shaknais @nixCraft

I was just thinking... do they really need a 32-bit int for that?? A bool or char would do it.

enoch_exe_inc

@rl_dane @shaknais @nixCraft Even then, for whatever reason, a Boolean is stored as a byte in memory. That’s seven whole bits of wasted memory. Also, that explains why bit arrays were so popular way back when memory and hard disk space was measured in kilobytes.

Gregory

@rl_dane @shaknais @nixCraft the size of bool is usually implementation-defined and a native "word-sized" one feels like it would be easier to deal with

rl_dane

@grishka @shaknais @nixCraft

Yes, it's classic optimize-for-speed-not-size. ;)

It's only a couple extra cycles to do the bitwise AND to unpack a packed bool array, but there are times where that would really count.

GolfNovemberUniform

@nixCraft jokes aside that is indeed a perfect an almost perfect function for automation.

RDogPinK

@GolfNovemberUniform @nixCraft donΒ΄t get it. wouldnΒ΄t a boolean be sufficient for this case?

GolfNovemberUniform

@RDogPinK @nixCraft I think so. I edited my comment. I don't like wasted memory.

DougMerritt (logπŸ˜… = πŸ’§logπŸ˜„)

@RDogPinK @GolfNovemberUniform @nixCraft
No; it never returns 0 / false, so it can't be just a boolean.

In type theory you could say that it's value is true or "bottom" if it is executed symbolically rather than physically.

Jan <3

@RDogPinK @GolfNovemberUniform @nixCraft I mean depending on if you’re writing old C. They didn’t have bools, just Ints. Bools were specified by the stdbool.h IIRC much later in time

EndlessMason

@RDogPinK
What if the computer is hibernating or thermal throttling or interrupted?

@GolfNovemberUniform @nixCraft

RDogPinK

@EndlessMason @GolfNovemberUniform @nixCraft yeah, but the function says "computer_on", not retrieve status ;)

EndlessMason

@RDogPinK
It already says "on-ness" is not boolean in the signature - I'm not a big "typed language" enjoyer, but afaik that means non-binary, baybeeeeeee

@GolfNovemberUniform @nixCraft

GolfNovemberUniform

@EndlessMason @RDogPinK @nixCraft A hybernated computer is not an operational computer. And what does thermal throttling have to do with it?

EndlessMason

@GolfNovemberUniform
If i have 4 cores and I turn off two the computer is half on.

If I have those same 4 cores but they're running at 50% of their usual clock speed to prevent over heating the computer is also half on.

@RDogPinK @nixCraft

EndlessMason

@GolfNovemberUniform
The underlying rule I'm using here is
"Half of the compute being available means the computer is half on".

Like one might expect from a water tap, or a dimmer lamp except with computers you know... The kind of thing one might represent in a int32?

@RDogPinK @nixCraft

wrosecrans

@RDogPinK @GolfNovemberUniform @nixCraft Consistency with other BeOS API's was probably more important than considering it strictly in isolation. It was a syscall, so using the standard "return an int" idiom probably made the most sense in context.

Philippa Cowderoy

@GromBeestje @nixCraft It's critically important to run this in a separate process to HCF()!

Gudroot

@GromBeestje @nixCraft This should also cover the temperature inside a supernova, so we are safe on that side ;)

Ian Turton

@GromBeestje @nixCraft I'm old enough to remember when computers were room sized and parts of it could be on fire while others continued to work relatively fine. There used to be an option to stop disks fast in the event that they were on fire.

P J Evans

@ianturton @GromBeestje @nixCraft
I met an IBM 360, which had a big red EMERGENCY switch. We were told to only use it if the machine was on fire.

jack

@GromBeestje @nixCraft how do you distinguish "some other value" from the temperature? should be re-written in Rust and return a `Result` element

Phosphenes

@JackEric @GromBeestje @nixCraft

Yeah that's what I was thinking. Maybe negative 10 Kelvin, below absolute zero?

If C++, should return a boolean with temperature as a pass by reference parameter.

Peter Mount

@GromBeestje @nixCraft reminds me of the old "lp0 on fire" error in some older Unixes

Chris [list of emoji]

@GromBeestje @nixCraft

Okay, I just googled it and it's real. I don't know whether to be delighted or horrified.

Chris [list of emoji]

@GromBeestje @nixCraft

Also (and sorry for the monologuing), I once witnessed a demo of the original dual-processor BeBox where the presenter showed how to turn off one or the other of the cores from the settings interface. He then turned off both of the cores, and it did exactly what you'd expect. While the computer rebooted, he segued on to how robust the filesystem was.

So, on reflection, this seems pretty on-brand for them.

theslik :tux: :firefox:

@nixCraft
Its the first thing you should check before starting your program logic.

Den of Earth

@nixCraft

int32 is_computer_on ();
{
return 1;
}

Alex Celeste

@DenOfEarth @nixCraft probably going to need some __attribute__((noinline)) or equivalent on that

Den of Earth

@aires @nixCraft
I could have coded it as a float but my insurance policy specifically excludes torches and pitchforks.

Asheville Charlie

@nixCraft
For some reason it reminds me of the halting problem..

DELETED

@nixCraft well, in the real world, there is no "perfect" anything, so why would functions be any different? this just proves the point even more

Dziadek

@nixCraft You can’t get more SchrΓΆdinger than that.

Maddie :patsMaddie:
@nixCraft use this instead of "true" for better code obfuscation
The Penguin of Evil

@nixCraft Absolute pig of a function to implement on a virtual machine that can be migrated

kami_kadse

@nixCraft

we should futureproof it. int32 isn't enough.

Cadbury Moose

@Victorsigmoid @kami_kadse @nixCraft

Was it the PDP-11 that had "?PWF" for a power failure - my forgettery seems to think so, but it was long ago... 3:O)>

(And the ASR-33 keyboard was _TERRIBLE_.)

Victor S Sigmoid

@Cadbury_Moose @kami_kadse @nixCraft Or possibly an LLM responder to make it relevant and marketable? Put some AI in it.

Electron Dance

@arose62 @nixCraft shredding device numbers was illegal, it had to be stopped

Locksmith

@nixCraft
I ran this function here. It returned a number that seemed a memory address. I checked the address and there was a string there: "I am."

What does this mean? What does this mean???

Luke

@nixCraft function Is_Computer_On return Boolean;

Jimmy Hoke :tardis:

@nixCraft Too much bloat. Why use a 32 bit integer? That takes up way too much RAM.

Weekend Editor

@nixCraft

It's a perfectly decent function... just a *partial* function, i.e., not defined on all its inputs.

Perfectly decent thing to be.

en.wikipedia.org/wiki/Partial_

mirabilos

@nixCraft int32 vorallendingen… 🀦

fennec :verified:

@nixCraft was the image description made by OCR? the function name reads "18_computer_on" instead of "is_computer_on"

vimproved

@nixCraft

If the computer isn't on, the value returned by this function is undefined.

goddamnit undefined behavior has gone too far

Western Infidels

@nixCraft It's not much use without the companion functions

well_turn_it_on_then() and

sheesh_why_do_I_have_to_think_of_everything_myself_around_here()

arceuthobium

@WesternInfidels @nixCraft it definitely needs an is_computer_plugged_in() extension

Robert Kist πŸ‡¦πŸ‡Ή πŸ‡ΈπŸ‡¬

@nixCraft SchrΓΆdinger's computer: it might be on, it might be off, you'll never know until you call this function

Paul Oldham 🏴󠁧󠁒󠁳󠁣󠁴󠁿 πŸ’› πŸ‡ΊπŸ‡¦

@nixCraft I'm reminded of the vital opcodes for power saving in CPUs
TPF turn processor off
TPO turn processor on

arceuthobium

@whynothugo @nixCraft I hate it when the software updates with a new random number

Kaley

@nixCraft sounds like a recipe for a secure memory leak issue to me πŸ˜›

david_chisnall

@nixCraft This is from the BeOS manual. As I recall, there is also an is_computer_on_fire() function, though I believe it always returned false in shipping versions.

mORA

@nixCraft I hope there will be a native version for 64 bit architectures anytime soon.

masukomi

@nixCraft a close runner-up for "perfect function" from BeOS

blausand 🐟

@nixCraft
bool is_computer();

// returns true if executed on a computer
// never returns when not executed on a computer

PS.: <pre> tag when, Mastodon?

Brian Swetland

@nixCraft It was a joke API, but that was secondary to it being a do-nothing syscall, useful for measuring system call overhead.

#BeOS

Go Up