Random syntax tweaks!

I am talking about tiny little syntax tweaks that you sometimes find yourself wishing existed.

My favorite is:


if(!(somevar > 0))

// Or, for less parenthesis...

if!(somevar > 0)

-wes

Is [icode]somevar <= 0[/icode] too arduous?

But yeah, list comprehensions.

My favorite:

public static void main(String args[]){
    OpenGL.createCallofDuty(800 /*How good you want your graphics to be*/);
}

But really I wish there was an IDE with code put into rectangles, then lines extruding from them, pointing to what they call and what they do. And when you click on them they show you the contents. That way you don’t have to scroll through 1200+ lines of code in a Display class.

Then maybe some kind of plugins to have an OpenGL pipeline format, and you just drag shaders into parts of the pipeline. And you could point variables of code into uniforms and stuff. cough future IDE idea cough

Not really Syntax, but I didn’t want to make a topic for it. :slight_smile:

Sounds a bit like LightTable.

That’s API/tooling level stuff, not really language level. Go do it!

I could make a game engine inside of netbeans or something.

And then, JMonkeyEngine was born.

Extrapolating from the original example, I really dislike how ‘not equals’ results in this spatially stretched operator (for lack of a better way to express it)


if(!this.getEngine.getType().getName().equals(that.getEngine.getType().getName())) {
   ^                                   ^
   |                                   |

I’d rather have: (ignoring all oddities that result from this)


if(this.getEngine.getType().getName().!equals(that.getEngine.getType().getName())) {
                                     ^^
                                     ||

To get more on par with the clarity of scripting languages:


if(this.getEngine.getType().getName() != that.getEngine.getType().getName()) {
                                      ^^
                                      ||

Patch rt.jar with new Object class:


public boolean notEquals(Object obj) {
        return (this != obj);
}

:persecutioncomplex:

EDIT: or for your != example, force string interning on construction. (obviously only works for strings)

That implementation would be a bug! [icode]return !this.equals(obj);[/icode]

no no no, it’s called a “random undocumented feature”

Fair enough.

Maybe something like this, even though we don’t NEED it. Damn IDEs wont let me have bodies of fields outside of actual containers…

public variables{
  int hello;
  String world;
}

static {
  variables.hello; //Is now static
}

default {
  stuff stuffes;
}

“if(!(somevar > 0))” works just fine in Java.

If I could tag users, I’d have you tagged as “2 chars 2 la”
Had to shave the zy off lazy there, just a bit too long.
That or “Syntax Error”

How about

public void init(String hello, String world, String hows, String it, int width, int height){

}

public void init(String (hello, world, hows, it), int (width, height)){

}

And

public void init(int width, int height){ 
     System.out.println(width, height);
}

public void init(int width, int height); System.out.println(width, height);

I would like some default values.

public void init(int width(800), int height(600), String title("Testing"))
{

}

init(default, default, "Hello World");

I hate java constructors.

public class SomeObject {
int a, b, c;
public SomeObject(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
}

Trying to work out how to make an eclipse plugin or something that would allow operator overloading/custom operators, even if the actual code was through custom annotations/bytecode manipulation via javaagent:


@Op("*")
public class vecCross {

    public static Vec3 cross(Vec3 a, Vec3 b) {
         return new Vec3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
    }
}

Allows for this (as a trivial example):


Vec3 v1, v2;

Vec3 cross = v1 * v2; // "complies" to cross = vecCross.cross(v1, v2);

I know Cas wanted something like that at one point.


public void jev(int x0, y0, x1, y1)
{
    System.out.println("aoeu");
}

I would love this. [icode]int x0, int y0, int x1, int y1[/icode] is incredibly repetitive. If you had multiple types of parameters in a function, it should look something like this:


public void jev(int x0, y0, double x1, y1)
{
    System.out.println("aoeu");
}

No idea if this would work realistically though.

  • Jev

@wes
Scala’s constructors are awesome.

class Vector2f(var x:Float, var y:Float) {

}

@Burnt
Why not just use scala? Its easy to do exactly what you want.

Actually I’m waiting for Rust 1.0, macro_rules!