Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Random syntax tweaks!  (Read 2063 times)
0 Members and 1 Guest are viewing this topic.
Offline wessles

JGO Wizard


Medals: 66
Projects: 4
Exp: 3 years


Profile picture isn't relevant.


« Posted 2014-05-31 20:09:37 »

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

My favorite is:

1  
2  
3  
4  
5  
if(!(somevar > 0))

// Or, for less parenthesis...

if!(somevar > 0)


-wes

Online BurntPizza
« Reply #1 - Posted 2014-05-31 20:16:41 »

Is
somevar <= 0
too arduous?

But yeah, list comprehensions.
Offline Spacebeans
« Reply #2 - Posted 2014-05-31 20:19:25 »

My favorite:

1  
2  
3  
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. Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online BurntPizza
« Reply #3 - Posted 2014-05-31 20:22:13 »

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.

Sounds a bit like LightTable.

just drag shaders into parts of the pipeline. And you could point variables of code into uniforms and stuff. *cough* future IDE idea *cough*

That's API/tooling level stuff, not really language level. Go do it!
Offline Spacebeans
« Reply #4 - Posted 2014-05-31 20:23:51 »

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

And then, JMonkeyEngine was born.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2014-05-31 20:23:58 »

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)

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


I'd rather have: (ignoring all oddities that result from this)
1  
2  
3  
if(this.getEngine.getType().getName().!equals(that.getEngine.getType().getName())) {
                                     ^^
                                     ||


To get more on par with the clarity of scripting languages:
1  
2  
3  
if(this.getEngine.getType().getName() != that.getEngine.getType().getName()) {
                                      ^^
                                      ||

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online BurntPizza
« Reply #6 - Posted 2014-05-31 20:25:50 »

Patch rt.jar with new Object class:

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


persecutioncomplex

EDIT: or for your != example, force string interning on construction. (obviously only works for strings)
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2014-05-31 20:26:49 »

That implementation would be a bug!
return !this.equals(obj);

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online Rayvolution

JGO Kernel


Medals: 189
Projects: 2
Exp: 1 year


Resident Crazyman


« Reply #8 - Posted 2014-05-31 20:27:50 »

That implementation would be a bug!

no no no, it's called a "random undocumented feature"

- Raymond "Rayvolution" Doerr.
Retro-Pixel Castles - Survival Sim/Builder/Roguelike!
LIVE-STREAMING DEVELOPMENT: http://www.twitch.tv/SG_Rayvolution
Online BurntPizza
« Reply #9 - Posted 2014-05-31 20:28:26 »

That implementation would be a bug!
return !this.equals(obj);


Fair enough.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spacebeans
« Reply #10 - Posted 2014-05-31 20:29:45 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public variables{
  int hello;
  String world;
}

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

default {
  stuff stuffes;
}

Offline wessles

JGO Wizard


Medals: 66
Projects: 4
Exp: 3 years


Profile picture isn't relevant.


« Reply #11 - Posted 2014-05-31 20:32:01 »

C and C++ do this in their classes. I always hated it; the java way just looks so neat:
1  
2  
3  
4  
5  
public int hai = 0;
public boolean helloo = 1;

public static int stat_hai = 0;
public static boolean stat_heloo = 0;

Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #12 - Posted 2014-05-31 20:32:43 »

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

Offline wessles

JGO Wizard


Medals: 66
Projects: 4
Exp: 3 years


Profile picture isn't relevant.


« Reply #13 - Posted 2014-05-31 20:33:51 »

Yes, but is 2 characters too long for my taste.

Online BurntPizza
« Reply #14 - Posted 2014-05-31 20:35:40 »

Yes, but is 2 characters too long for my taste.

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"
Offline Spacebeans
« Reply #15 - Posted 2014-05-31 20:37:47 »

How about

1  
2  
3  
4  
5  
6  
7  
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

1  
2  
3  
4  
5  
public void init(int width, int height){ 
     System.out.println(width, height);
}

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

JGO Wizard


Medals: 66
Projects: 4
Exp: 3 years


Profile picture isn't relevant.


« Reply #16 - Posted 2014-05-31 20:40:36 »

While we are on constructors, hows about something like C's initialization lists?

Offline Longarmx
« Reply #17 - Posted 2014-05-31 20:43:05 »

I would like some default values.

1  
2  
3  
4  
5  
6  
public void init(int width(800), int height(600), String title("Testing"))
{

}

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

Offline saucymeatman
« Reply #18 - Posted 2014-05-31 20:45:59 »

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;
}
}
Offline wessles

JGO Wizard


Medals: 66
Projects: 4
Exp: 3 years


Profile picture isn't relevant.


« Reply #19 - Posted 2014-05-31 20:48:47 »

@saucy
Like I said, initialization lists.
1  
2  
3  
final int hai;
final int he;
public Example(int hai, int he) : hai(hai), he(he) {}

Online BurntPizza
« Reply #20 - Posted 2014-05-31 20:54:50 »

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:

1  
2  
3  
4  
5  
6  
7  
@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):

1  
2  
3  
Vec3 v1, v2;

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


I know Cas wanted something like that at one point.
Offline kpars

JGO Wizard


Medals: 77
Projects: 4
Exp: 3 years


Extreme Typist.


« Reply #21 - Posted 2014-05-31 20:56:11 »

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

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

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

No idea if this would work realistically though.

- Jev

Offline saucymeatman
« Reply #22 - Posted 2014-05-31 20:56:41 »

@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.
Online BurntPizza
« Reply #23 - Posted 2014-05-31 20:57:15 »

Actually I'm waiting for Rust 1.0, macro_rules!
Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #24 - Posted 2014-05-31 21:29:32 »

Speaking of Rust, it allows the syntax that OP wanted:
1  
2  
3  
if !(someVar > 20) // Don't need parenthesis because block statements require braces.
{
}

(In fact, if configured, it throws compiler warnings when you have unneccessary parenthesis.)

And macro_rules! is just awesome.

For last LD I used it to expand this:
1  
tile!(1 Grass : TileGrass(0,1))

Into a full Tile class with texture coordinates etc., plus a static instance (Grass) and ID (1).

Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #25 - Posted 2014-06-01 10:15:25 »

Keep in mind, though, guys, the more complex the syntax becomes, the harder it's going to be for newbies to get into the language. That's one of the problems of learning scala.

Here are a couple of different ways of printing out each String in an array:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
val strings = "this is a string with different things in it".split(" ")

// Way 1:
for (str <- strings) Console.print(str)
// Way 2:
strings.foreach { str => Console.print(str) }
// Way 3:
strings.foreach((str) => {
  Console.print(str);
})
// Way 4:
strings.foreach((str) => Console.print(str))
// Way 5:
strings.foreach(Console.print(_))
// Way 6:
strings.foreach(Console.print)


Scala's syntax is rich, that's a plus on the one hand and a minus on the other.
It makes it harder to learn and sometimes you wonder even as experienced programmer why some syntax doesn't work.

Personally, I'm all for a concise simple syntax, which is extensible. Lisp and it's dialects are incredibly good at that. Concise, simple and very extensible. It shows the perfect combination of minimalism and extensibility Smiley

There is a talk "Growing a Language" by a genious "Guy Steele", who worked a lot with Lisp-languages and helped with designing a lot of languages, one of them being java. I really strongly recommend watching it completely Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline atombrot

Senior Member


Medals: 10
Projects: 1



« Reply #26 - Posted 2014-06-01 13:45:02 »

A very simple one that I miss in java is the ?? operator from C#. If used at the right places it can make the code more concise without loosing any readability.

From http://msdn.microsoft.com/en-us/library/ms173224.aspx
Quote
The ?? operator is called the null-coalescing operator. It returns the left-hand operand if the operand is not null; otherwise it returns the right hand operand.

Here is a silly example:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
public class Foo
{
   private string _instance;

   public string GetInstance1(){
      if(_instance == null){
         _instance = "instance";
      }
      return _instance;
   }

   public string GetInstance2(){
      return _instance == null ? (_instance = "instance") : _instance;
   }

   public string GetInstance3(){
      return _instance ?? (_instance = "instance");
   }
}


Offline Danny02
« Reply #27 - Posted 2014-06-01 14:10:13 »

This ?? operator just tries to hide a problem instead of fixing it. Getting rid of null and using something like a Option type is way better in my opinion.
Offline ags1

JGO Ninja


Medals: 55
Projects: 2
Exp: 5 years


Make code not war!


« Reply #28 - Posted 2014-06-01 14:17:12 »

Groovy has the ?: operator for nullifying nulls:

ifThisIsNull ?: useThisValueInstead

Actually it means if the first value evaluates to false (as null does) then use the second value.

One other feature I would like from Groovy is language level support for collections...

Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #29 - Posted 2014-06-01 16:26:47 »

This ?? operator just tries to hide a problem instead of fixing it. Getting rid of null and using something like a Option type is way better in my opinion.

Exactly. It's called the Billion Doller Mistake by the "creator" of
null
, Tony Hoare.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Pages: [1] 2
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (14 views)
2014-09-01 10:59:12

TehJavaDev (23 views)
2014-08-29 06:26:30

CopyableCougar4 (29 views)
2014-08-23 07:31:30

atombrot (41 views)
2014-08-19 21:29:53

Tekkerue (38 views)
2014-08-16 18:45:27

Tekkerue (35 views)
2014-08-16 18:22:17

Tekkerue (24 views)
2014-08-16 18:20:21

Tekkerue (34 views)
2014-08-16 18:12:11

Rayexar (72 views)
2014-08-11 14:49:23

BurntPizza (48 views)
2014-08-10 09:09:32
List of Learning Resources
by Longor1996
2014-08-16 22:40:00

List of Learning Resources
by SilverTiger
2014-08-06 07:33:27

Resources for WIP games
by CogWheelz
2014-08-02 04:20:17

Resources for WIP games
by CogWheelz
2014-08-02 04:19:50

List of Learning Resources
by SilverTiger
2014-08-01 04:29:50

List of Learning Resources
by SilverTiger
2014-08-01 04:26:06

List of Learning Resources
by SilverTiger
2014-07-31 23:54:12

HotSpot Options
by dleskov
2014-07-08 13:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!