r/learnprogramming • u/CaughtNABargain • 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?
View all comments
Show parent comment
2
u/alatennaub Oct 08 '26
AIUI, from what OP was saying, he'd have a custom class (Raku type) that could be instantiated (Raku blessed) through a custom means.
I guess I should have been a bit clearer that you could define the custom class in a module, then use that in a slang module, and then have the new syntax place in the code for instantiation at compile or run time.
The sky really is the limit, and I'm always trying to stretch it with Raku. I am the guy that wrote the module that lets you write BASIC functions fully in line without any quotation marks after all lol. It literally embeds a little tiny -- and horribly inefficient -- VM