Java "Mods"

I was in class today and I started thinking, what if someone figured out a way to make Java “mods”, eg, they could add little pieces of their own syntax directly into the language, not as a library. There could be a plugin for Eclipse that would be able to grab the mod from a supplied URL and install it into your Java installation. Or maybe even a Linux application and Windows one. And a Mac app at that.

A little example:
I want to be able to add in unsigned ints if you are writing something for networking or whatever so I program a little “mod” in, I don’t know, Java?

I really have no clue how you would develop something like that, so that’s why I’m asking.
Maybe even Oracle comes out with a little dev library that you can use to create new primitive data types or whatever else. Maybe your own customized version of arrays, so on and so forth. Now I’m just dreaming…

Is there such a thing?

IMHO - I think its almost impossible if take like example unsigned ints – math operation with primitive types do Virtual machine and you can’t change it so other can simple use you application with base Oracle VM, if you change it you must provide new VM with you’r program.
You can write macro for eclipse for unsigned ints , let say that auto convert to Long, but it any case this not give you any performance, only add new visual word in code :wink:
You can do same by creating class with static wrap function)

P.s I newer write eclipse plugins so I can be wrong :wink:

Man, that would be awesome! How cool would it be to allow the coders to write code that they’ll use to… code? It would allow java to get some features I wish it had.

Id like a “mod” for the c++ enum declaration, as far as I can tell it looks much simpler.

Either way im sure those more creative than I would be creating mods with much cooler stuff like new logic statements and such!

Maybe you could find a way to hack into the AST during compilation.

I see lots of potential confusion in this proposal. Imagine a world where C++ like operator overloading wasn’t confined to specific classes but was given free reign throughout the JVM. Imagine trying to post some problem code for others to assist with debugging and either a)having to explain what the “non-standard” code in your post did for those unfamiliar with the “mods” you use, or b)rewriting your “non-standard” code constructs in “standard” form just to get assistance. You’re also introducing another layer of potential bugs between your typed code and the generated class files. If you find the language you’re working in too constraining, or too complex for a given task, it’s probably better to look for a language more suited for the task than to attempt to piecemeal fixes into the core of the one you’re using.

Ah I see the sense in that. Still, I think it would be an interesting thing to play around with.

Isn’t that one of the kickass features of Lisp?

Unsigned integer support (via method calls) is in JDK8. Adding new syntax elements involves adding them to the parser and lowering them (either at the AST or bytecode level) into JVM ops. There are libraries to do this. invokedynamic allows defining pretty much arbitrary endpoints so some reasonable low-level tools are there for doing all kinds of wacky and not-so-wacky things.

Sigh: operator overloading is awesome…C++ problems have nothing to say about that feature.

Big Fat IMHO sorry for that:
operator overloading it bullshet, and good programmers newer should use them,
the reason behind this –
THIS FUNCTION CAN’T BE PROPERLY FINDET WITH IDE USING FUNCTION CALL SEARCH and Refactoring
+
THEY HARD TO CODE UNDERSTANDING – PPL THAT SEE YOU CODE FIRST TIME (OBj Girl + OBj Wood) = ???
OBj Girl.Pick(OBj Wood)
OBj Girl.See(OBj Wood)
OBj Girl.StepOn(OBj Wood)

If you what short function you may do


int x = bla;
int y = bla;
int z = bla;
int time = bla;
.....

public My_Mega_Obj Plus_X(My_Mega_Obj a){
	this.x += a.x;
	return this;
}
public My_Mega_Obj Plus_Cord(int p){
	x += p;
	y += p;
	z += p;
}

// if you need this crap
public My_Mega_Obj Plus(My_Mega_Obj a){
	return P(a);
}
public My_Mega_Obj P(My_Mega_Obj a){
	return Plus_X(a)
}

obj_A.Plus_X(obj_B)
or
obj_A.Plus(obj_B)
or
obj_A.P(obj_B)
 
and
obj_A + obj_B = bullshet


most frequently that i need and java don’t have is multy parent object, not only interface.
So I must use
Class A
Class B extend A
Class C extend B
Class D extend C
Class E extend D
Class F extend E

becouse i separate code, i hate 2k - 5k code files =)

And this is annoying
But this is architecture JVM not some restriction java compilator.
You can’t change it simple write mod for eclipse :wink:

But we have many option – use alternative JVM or make new one, I am not rd for this but this is possible ^^

About operator overloading - in my opinion it is very useful, especially if you are making a lot of operations like vector math or matrix math. :slight_smile: Pure syntatic sugar, but it makes code much cleaner and more understandable.

@Icecore: I’m a reasonably competent programmer but I don’t see any reason to re-cover operator overloading in any detail. For non-primitive types you’re effectively writing in assembly language which really sucks (see: HERE) and defeats the purpose of programming in a high-level language. You should ask yourself why there are very few mathematical libraries for java (over non-prim types) and why they have so few features (of course operators isn’t the only problem).

Something I’ve never mentioned is that I have a DSL for mathematical programming. If I lower it into “macros” of a more basic programming language it multiples the code size by a factor of around 100x. Macro expansion pushes that number up to several hundred. It also does code-specialization so effectively every operator “call” could be lower into a unique piece of code… i.e. there is no one-to-one mapping of operator to method call…there may not even be a method call…and it’s aware of multi-operator transforms. As I’ve said every time this topic has been raised: “forget C++”. People don’t look at C++ and say: “Man class based object oriented really sucks” so don’t think that about any particular feature that C++ happens to support. If you want to write hundreds of lines of code to my handful…more power to you. I prefer to be lazy.

P.S. Colored text…nice.
P.P.S. Your example is non-sense. If someone wants to write garbage code they have no problems regardless of want language feature you chose to provide.

Others have already addressed unsigned ints, but for more general transformations, see Project Lombok. It rewrites the AST during compilation. Consequently this only works with supported compilers - eclipse and javac/netbeans in this case - and extending it is somewhat beyond comprehensible imo. Check out lombok-pg if you’re interested in exploring that route.

Alternatively, one can use bytecode transformation libraries like ASM or javassist. At least ASM can be used as both as a compile-time step or runtime - via a custom classloader. It is however, to the best of my limited knowledge, not possibly to hack in new syntax this way.

BTW, I just learned about the Graal project. It’s a subproject of OpenJDK and it is an interesting lib to have your own language run on the JVM. You parse your language and build up an AST with the Truffle lib of this project. After that you can run the AST and the Graal compiler which is already included in the latest JRE will compile it to Java-Bytecode on the fly.

Also, they have an example parser for Java so you can probably add your own syntax quite “easy”.

Agree the problems in code always goes from ppl, and programming language don’t change that.

Only mega pro programmers can use it properly ^^

Well I am gonna look that up right now, and become a mega pro programmer. Off to a valiant adventure on Google :point: