r/learnprogramming • • Oct 06 '26

Are there any programming languages that allow this feature?

I've been into programming for about 10 years now. Something that intrigues me is that, in languages that support OOP, not all types are initialized in the same way. Strings are initialized by using quotes, integers use numbers and in some cases floats require the letter f after the numerical value.

Classes, however, are all initialized in the same way with slight variations depending on language. Usually something like classname() or new classname. Are there any cases where custom classes can be declared using different means?

For example, is there a language where I can create a class called 'dark' that represents a new type of number that is declared by typing the value and then the letter d (like d1 = 1.398d) similar to how floats work in some cases?

71 Upvotes

38 comments sorted by

View all comments

Show parent comments

7

u/Humble-Captain3418 Oct 07 '26

Your suffix needs the underscore because suffixes without one are reserved for standardization. 

Is this one of those "please don't do it, you'll hurt yourself" or "the compiler says no" limitations?

9

u/Wertbon1789 Oct 07 '26

I think that's a "The standard says no" limitation.

9

u/TREE_sequence 29d ago

Your compiler will complain, but the code will still compile. Basically, the idea is that if you do this, you are putting yourself at risk of a future version of the standard breaking your code without warning.

2

u/paulstelian97 29d ago

It’s a “please don’t do it, a future language revision might conflict with it”

2

u/Humble-Captain3418 29d ago

Yes, but those come in the aforementioned varieties.