DEV Community

Calin Baenen
Calin Baenen

Posted on

3 1

Would `repr` keyword fit into a C-like language (Janky)?

I was wondering if a repr keyword would work well in my C-like language, Janky.

Here's an example:

public class Character {
    private final repr char c;
    public Character(char c) this.c = c; // Don't mind the fact there aren't braces. This is prototype (and shorthand) syntax.
}
Enter fullscreen mode Exit fullscreen mode

Basically, the idea is that it lets you represent your class as another datatype (primitive or class) regardless of whether it extends from that type or not.

This can also be used with methods (though, said "repr-methods" mustn't take any arguments, adding parameters to the repr will cause an error):

public final class Random {
    private int seed = 0;
    private final int[] nums = {
        0, 5, 2, 1, 6, 3, 7, 0, 10, 9, -1, 5
    };
    public repr int nextInt() {
        final int comp = try nums[seed] catch -4;
        final int ns =  Math.round(
            Math.dmxbmn(seed, nums[-1])
        )+comp; seed = ns;
        return ns;
    }
}
Enter fullscreen mode Exit fullscreen mode

So, this Random class will return a (seemingly) random int every time nextInt() is called. And, as repr makes it out, whenever you do Random r = new Random(); 100+r; the 100+r becomes short for 100+r.nextInt().

Of course, you get the same result when passing r to a method that takes an int.




So... What do you think?
Is this a good or a bad keyword idea? Useful or useless (or maybe in between)?

Let me know your thoughts.

Thanks!
Cheers!

Image of Wix Studio

2025: Your year to build apps that sell

Dive into hands-on resources and actionable strategies designed to help you build and sell apps on the Wix App Market.

Get started

Top comments (0)

Imagine monitoring actually built for developers

Billboard image

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay