449
To type or not to type ? (sh.itjust.works)
top 22 comments
sorted by: hot top controversial new old
[-] rikudou 22 points 1 year ago

Solution:

export type unsigned_int = number

[-] shootwhatsmyname@lemm.ee 2 points 1 year ago

export type App = unknown

[-] vox@sopuli.xyz 16 points 1 year ago* (last edited 1 year ago)

tbh c/c++ type system is super fucked up
What the fuck is unsigned long long int just call it u64

[-] Johanno@lemmy.fmhy.ml 6 points 1 year ago

Well it isn't always 64 bytes. Some architectures differ.

[-] darcy@sh.itjust.works 10 points 1 year ago
[-] akariii@lemmy.blahaj.zone 3 points 1 year ago

you can just use unsigned long long (drop the int) or, if it bothers you that much, uint64t but keep in mind that yhe size of unsigned long long may vary depending on the architecture

[-] fiah@discuss.tchncs.de 12 points 1 year ago

const a: any = "You have no power here!"

[-] socsa@lemmy.ml 2 points 1 year ago

laughs in reinterpret_cast

Is it even a programming language if you can't casually introduce type overflows?

[-] lowleveldata@programming.dev 12 points 1 year ago

tbh unsigned int scares me too. I just use int anyway to avoid strange things happening.

[-] zeropublix@lemmy.ml 12 points 1 year ago

The use of it quite limited in the every-day coders life. People acting like they be using 500TB databases these days.

[-] Sallen@lemmy.world 22 points 1 year ago

Embedded software devs still exist btw

[-] angrymouse@lemmy.world 3 points 1 year ago

Stop lying, who in the modern world would need embedded systems?

[-] kakes@sh.itjust.works 6 points 1 year ago

I don't see a use for embedded systems that can't be adequately replaced with a Windows PC smh.

[-] socsa@lemmy.ml 1 points 1 year ago

Netcode. I make my own layer 2 headers sometimes.

[-] Doombot1@lemmy.one 7 points 1 year ago

I use uints every day at work. They’re very useful for cases when you’ve only got a single byte or two bytes to work with. E.g. an 8-bit int will only get you to a max of 127, but of course an unsigned 8-bit gets you to 255. Similar concept with 16/32/64s. Very useful when you’re working with small amounts of available memory, such as when writing code to go on ASICs.

[-] bioemerl@kbin.social 1 points 1 year ago

Yep, I always default to the largest possible type because compute is less valuable than my time on the weekend and the potential for any sort of overflow.

Long

Double

Big int

Etc.

[-] Anomandaris@kbin.social 11 points 1 year ago* (last edited 1 year ago)

I don't know if I'd go that far. If you're talking about a quick script then sure, whatever gets the job done. But for any actual project the use of good, consistent typing does a lot for readability and future-proofing. And in strongly-typed languages it can have a notable affect on the overall functionality too.

If you can't tell from context whether something is a float or if it'll overflow the int max then you probably need to re-think the entire method.

[-] darcy@sh.itjust.works 2 points 1 year ago

why not just compile with overflow checking? assuming the number should not reach the limits

[-] bioemerl@kbin.social 1 points 1 year ago

The compiler doesn't know what numbers are going to go into a variable, that's a runtime thing. They might prevent a crash that way, but a crash or not doesn't matter when people need the number in the database and the database doesn't let you put the number in the database.

[-] darcy@sh.itjust.works 1 points 1 year ago* (last edited 1 year ago)

i mean, at least with rust, running in debug mode (or release with flags) will hard panic if an overflow occurs, bc it checks everytime a number is changed. it is obviously less performant to do this, so it does not check when running in release/production mode. the problem is if you need to have no overflows occur, it is better to throw an error and exit the program, than cause unexpected behaviour, eg. as an incorrect, but existing array item. this could be hard to find the cause of the bug if it doesnt throw

[-] bioemerl@kbin.social 2 points 1 year ago

I'm a C# dev so I forget that anything that's not this case even exists. Agreed 100 percent.

[-] darcy@sh.itjust.works 7 points 1 year ago

typescript is still weakly typed.

it is just a hacky static analysis that compiles to weakly typed js

load more comments
view more: next ›
this post was submitted on 13 Jul 2023
449 points (98.3% liked)

Programmer Humor

32410 readers
295 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS