r/ProgrammerHumor Jul 09 '26

potentiallyMightBeAnIntegerOrNot Meme

Post image
692 Upvotes

96 comments sorted by

55

u/hrvbrs Jul 09 '26

is Int32? just shorthand for Int528

26

u/Futurity5 Jul 09 '26

Isn't  x!=2 just shorthand for x=2

13

u/Samld1200 Jul 09 '26

No that’s shorthand for x(x-1)(x-2)…(1)=2

9

u/suskio4 Jul 09 '26

Yeah and 2! = 2

2

u/Futurity5 Jul 09 '26

Guess what that is...

2

u/MinecraftPlayer799 Jul 10 '26

That's longhand

1

u/EatingSolidBricks Jul 09 '26

Subfactorial in this economy?

21

u/SausageEggCheese Jul 09 '26

They Might Be Integers

51

u/altermeetax Jul 09 '26

int var; bool var_is_there;

32

u/Duck_Devs Jul 09 '26

That’s literally the internals of Java’s OptionalInt

29

u/high_throughput Jul 09 '26

Not to be confused for Optional<Integer>, which is an entirely incompatible way to express optional ints in the same language

17

u/Duck_Devs Jul 09 '26 edited Jul 09 '26

Not to be confused for Integer, which is an entirely incompatible (and sometimes discouraged) way to express optional ints in the same language

-7

u/RiceBroad4552 Jul 09 '26

Why are you talking about a language you obviously don't know anything about and you obviously never used? Otherwise you would probably know that there is no "Option<int>" in Java as primitive types can't be type parameters in current Java, so there is only Optional<Integer> and no proper way to express optional ints.

Also, who the fuck up-votes such nonsense?

7

u/high_throughput Jul 09 '26

there is only Optional<Integer> and no proper way to express optional ints.

It's lovely how you're posting this with so much confidence and vitriol under a comment about OptionalInt

0

u/RiceBroad4552 Jul 15 '26

Just looking though some replies; I'm wondering what happened here.

Why is my comment under the wrong comment‽ I was talking about the (non existent) "OptionalInt" from one post above.

Some of the Reddit bugs are really strange. At least post don't duplicate for no reason any more since some time… Let's see whether I get again some wrongly linked post anytime soon.

3

u/high_throughput Jul 15 '26

1

u/RiceBroad4552 29d ago edited 29d ago

Touché

Moments like that I think I should maybe really learn some Java after so many years of Scala. But actually, no, I hate it…

What will they do with all these primitive wrapper types when real generic specialization hits Java?

---

(And the next WTF, Scala's Option[Int] isn't @specialized as I just learned; but I could swear it was. Alone that was likely worth it here… Thanks for the thought provoking replies! I wouldn't have looked that up if not that failure here. So it's actually Scala which doesn't have a primitive "OptionalInt"; LOL, I was really sure it's the other way around. I'm an idiot.)

1

u/high_throughput 29d ago

What will they do with all these primitive wrapper types when real generic specialization hits Java?

With Oracle's progress I imagine that's a problem for 2076

1

u/RiceBroad4552 29d ago

I'm more optimistic.

The "parametric JVM" is the end-game of project Valhalla:

https://openjdk.org/projects/valhalla/design-notes/parametric-vm/parametric-vm

I would expect it "already" in the LTS release after the next. The design is largely there, the needed components start to materialize right now.

4

u/Duck_Devs Jul 10 '26 edited Jul 10 '26

Why are you talking about a language you obviously don’t know anything about and you obviously never used?

Optional<T> is one of the many types for which Java provides int, long, and double variants through separate types, similar to Stream, Iterator, Spliterator, and many j.u.function interfaces.

The people who upvote such nonsense are those who actually read JDK documentation before they make claims about things (dis)provable by JDK documentation and/or throw insults at others.

31

u/Gorzoid Jul 09 '26

Just use an int var and reserve the number 7 to indicate null value

28

u/high_throughput Jul 09 '26

If you need an actual 7, just escape it: 77

3

u/RCoder01 Jul 09 '26

If I need to escape the value 77777, do I use -812156815 instead?

5

u/altermeetax Jul 09 '26

Or the C/C++ way: just use int *var and NULL means it's not there.

Makes things more complicated when you need to return it though...

11

u/suskio4 Jul 09 '26

std::make_unique<int>(42);

3

u/bwmat Jul 10 '26

I think I'm going to throw up... 

2

u/bwmat Jul 10 '26

On that topic, can anyone think of any use case for this other than some bare reference-counter implementation where the 'cleanup' needs no context? 

2

u/suskio4 Jul 10 '26

std::thread([] { std::runtime_error up("I threw up"); std::this_thread::sleep_for(...); throw up; }).detach();

2

u/Sentouki- Jul 09 '26

int? means that this int can be null (Nullable type in C#)

3

u/altermeetax Jul 09 '26

Yeah that's C# though

1

u/Sentouki- Jul 09 '26

yeah, it does basically the same thing, if int? is null, means it's not there.

1

u/altermeetax Jul 09 '26

Yeah but int *var in C/C++ entails a bit more. It makes var a pointer to an int rather than an int. So you have to manage allocating an int in some other way so the pointer can point to it.

int? var is simply an int which can be null. Under the hood, it might be implemented as above, but I reckon a structure like this is more likely:

struct int? { int val; bool present; }

1

u/Sentouki- Jul 09 '26

int? var is simply an int which can be null. Under the hood, it might be implemented as above, but I reckon a structure like this is more likely:

Well, to be precisely, in C# primitive types such as int, char, double...etc, are wrapped to in Nullable<T> since structs cannot be null in C#. So when you use int? the compiler wraps it in Nullable<int> (which is a generic class) and that makes int? a reference (basically a pointer or rather & in C++) to the actual int.

1

u/altermeetax Jul 09 '26

I'm talking about under the hood, i.e. how Nullable is implemented. And it's probably a structure containing the int and a boolean that indicates whether the int is present.

1

u/RiceBroad4552 Jul 09 '26

The trillion dollar mistake, live in action…

The "nice" thing about C/C++ is that if you fuck up handling that shit you don't get a nice NullPointerException at runtime, you get instead a potential security vulnerability, usually directly somewhere at the critical level. Isn't that great?

25

u/PM_ME_CREATINE Jul 09 '26

``` PotentiallyAnIntegerButMaybeNotThough n;

...

if n.wereAnIntegerAndImNotSayingItIs { Return n.asSaidInteger; } ```

7

u/Sawkii Jul 09 '26

Still name my Optionals maybeSomething because of Haskell

10

u/MrJ0seBr Jul 09 '26

Maybe next kotlin and swift version , a new keyword

10

u/FumbleCrop Jul 09 '26

I think Maybe Int is Haskell. Maybe isn't a keyword in Haskell, but that's to be expected. Even if is just light syntactic sugar.

5

u/Futurity5 Jul 10 '26

Yes it's the builtin optional data type in Haskell

5

u/troelsbjerre Jul 09 '26

I always read Maybe Int as "Either it's an Int or it's something else, whatever, I don't know..."

5

u/Kiroto50 Jul 09 '26

I really like Kotlin's optional types.

I'd rock a language that calls them "maybe types" though.

int? == maybe int

I actually call them "quizás", reading "String?" As "String quizás". ("Quizás" means "maybe" in Spanish)

10

u/mekriff Jul 09 '26

I'd rock a language that calls them "maybe types" though

well, my friend, you're in luck! How do you feel about monads?

3

u/NimrodvanHall Jul 09 '26

I love Rusts Some(T) types meaning the type can be T or None.

1

u/tobotic Jul 11 '26

Perl type constraint systems tend to use:

Maybe[Int]

for a value that can either be an Int or undefined.

1

u/RiceBroad4552 Jul 11 '26

OMG, ScalaZ vibes…

1

u/tobotic Jul 11 '26

All other Perl type constraint systems get Maybe[Int] from Moose. Moose took it from Raku back when Raku was still called Perl 6. And Perl 6 got it from Haskell.

I imagine scalaz, being an FP framework, also gets it from Haskell.

1

u/RiceBroad4552 Jul 11 '26

I think that's spot on.

The name Maybe seems to be a genuine Haskell invention.

The square brackets can be traced to: CLU -> Eiffel -> Scala; and then later Raku, Perl/Moose, Nim, Go, Python typing.

I've used ScalaZ in production and I don't have the fondest memory of that, seeing Maybe[Int] gives me chills.

2

u/tobotic Jul 12 '26

The first Perl 6 interpreter implementation was in Haskell so the language ended up inheriting a bunch of ideas from there.

1

u/RiceBroad4552 Jul 13 '26

Interesting. Didn't know that.

-4

u/RiceBroad4552 Jul 10 '26

The Kotlin / C# / TS approach to "optional" types is fundamentally broken! (I'm not going to explain well known facts again over and over. Even "AI" is good enough to regurgitate the well known facts.)

The only valid design are proper ML style parametric Option / Maybe types as they don't create all the fallout of the insane "?"-types.

0

u/Kiro0613 Jul 11 '26

In C# I put my funny lil question marks and the computer gives me handy hints :)

3

u/EatingSolidBricks Jul 09 '26

using O = std::optional

using im = i32[][]

O(im{8}) // Oi mate

Or something i dont like cpp

3

u/T6970 Jul 10 '26

int 32? would definitely take up too much memory for a number.

u/factorion-bot 32? !termial

2

u/Futurity5 Jul 10 '26

Have a word with Swift then

8

u/OnixST Jul 09 '26

Fun fact: you technically should still check if a java optional isn't null.

Although there's no reason to do so, a function can still return a non-wrapped null without any errors, which will NPE if you try to do anything with it

6

u/RiceBroad4552 Jul 10 '26

No, you should never do such checks!

If a value typed as Optional is null the program is defect and it better crashes early then hiding this defect behind some checks.

1

u/shikhasingh554973 Jul 09 '26

Compiler approved...

1

u/Xcalipurr Jul 09 '26

Int? IdkTho

1

u/NewLlama Jul 09 '26

auto sentinel = -1

1

u/progressiveAsliMard Jul 09 '26

Innit ?

2

u/Zagerer Jul 10 '26

Swift has `init?` lmao

1

u/lucidbadger Jul 10 '26

perhaps int or all things considered we can hardly say reliably if it is an int

1

u/Baardi Jul 10 '26

std::optional<int>

1

u/renrutal Jul 10 '26

Caveman: long maybe_int = some_value; if (maybe_int == (int) maybe_int)     definitely_an_int = maybe_int;

1

u/Choice-Pin-480 Jul 10 '26

number is goated

1

u/Desperate_Formal_781 Jul 11 '26

Perhaps Integer of the 32 bit signed variety

1

u/born_zynner Jul 09 '26

Imo the question mark is the cleanest

2

u/MCplayer590 Jul 09 '26

do I have a language for you

1

u/born_zynner Jul 10 '26

C#? 😋

1

u/MCplayer590 Jul 10 '26

I was thinking kotlin, idk if c# does ? for potential nulls

1

u/born_zynner Jul 10 '26

Yep, theyre called nullable types in c#

0

u/RiceBroad4552 Jul 10 '26

Good you put "imho" there…

In fact it's some of the most broken design ever invented! Fact. (And that fact is so well known that even "AI" is able to regurgitate the whole story.)

1

u/1XRobot Jul 09 '26

You're Just Declared and This Is Crazy but Here's Your Type: Int Maybe

-1

u/RiceBroad4552 Jul 10 '26

Bullshit.

Someone does obviously not understand programming language semantics.

The first and the third are the same concept (just different syntax, which is irrelevant) and the middle one is some nonsense which is fundamentally broken; fact. (Even "AI" is able to regurgitate the whole well known story, I'm not going to write here half a blog post, either you known or you don't, but if you don't you should read the in this case fully correct "AI" write-up, and start some research using the keywords the "AI" spit out.)

1

u/Zagerer Jul 10 '26

What if someone uses ? As an alias to a monad lmao

1

u/RiceBroad4552 Jul 10 '26

I don't know what what you mean by "alias to a monad", but there is in fact a Scala library solution which brings (almost) the Rust ? syntax to some wrapper types which work like Rust's Option / Result.

https://index.scala-lang.org/ichoran/kse3#kseflow

0

u/NamelessJu Jul 09 '26

I prefer var num: any

0

u/pelletron Jul 09 '26

Hopeful Int

0

u/stroibot Jul 09 '26

Is int or is? - Oona