Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (744)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (825)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Core Java Syntax  (Read 6731 times)
0 Members and 1 Guest are viewing this topic.
Offline Hydroque

JGO Coder


Medals: 25
Exp: 5 years


I'm always inspiring a good time.


« Posted 2016-03-13 21:00:58 »

I wonder if they will ever revamp the actual text portion of Java. persecutioncomplex

I would love something like this...
1  
2  
3  
public void doSomething(float x, y, int sx, sy) {

}



You think I haven't been monitoring the chat? http://pastebin.java-gaming.org/c47d35366491fHere is a compilation <3
Offline Riven
Administrator

« JGO Overlord »


Medals: 1327
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2016-03-13 22:02:40 »

Well, having more than 3-4 parameters is a sign of code-smell, so why would be lower the barrier Smiley

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

JGO Coder


Medals: 25
Exp: 5 years


I'm always inspiring a good time.


« Reply #2 - Posted 2016-03-13 22:57:40 »

Because I don't want to type float 5 times :/ nor double 3

You think I haven't been monitoring the chat? http://pastebin.java-gaming.org/c47d35366491fHere is a compilation <3
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ags1

JGO Kernel


Medals: 356
Projects: 7


Make code not war!


« Reply #3 - Posted 2016-03-13 23:17:57 »

there is foo(long arg, String... otherArgs).

Offline nsigma
« Reply #4 - Posted 2016-03-14 16:47:56 »

Because I don't want to type float 5 times :/ nor double 3

I think you should re-read @Riven's answer!  Grin

Still, as much as I dislike the enhancement you're suggesting, I think I prefer it to local variable type inference.

1  
var list = new ArrayList<String>();


Put the two together and we could have -

1  
public void doSomething(var x, y, sx, sy) {}


Joy!  TL;DR what we have could be a lot worse - I'd rather have verbose and legible.

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline Roquen

JGO Kernel


Medals: 516



« Reply #5 - Posted 2016-03-15 16:12:38 »

In the Java mindset you can't tell if the missing type is an error...so that will never happen.
Offline Hydroque

JGO Coder


Medals: 25
Exp: 5 years


I'm always inspiring a good time.


« Reply #6 - Posted 2016-03-15 18:09:34 »

I still like my way better.

Usually using var whatever is redundant because in times of building an object, you could just do... (for example)

1  
[i]function[/i](new ArrayList<String>().add("abc").add("def"));

You think I haven't been monitoring the chat? http://pastebin.java-gaming.org/c47d35366491fHere is a compilation <3
Offline matt_p
« Reply #7 - Posted 2016-03-17 12:20:49 »

...

That will not work because the compiler does not know what type var would be if you use it as method parameter.
It works just for local variables, and only if it is clear what type it is. E.g. var x = null; or var x; would not be possible at all.

@topic
Never had this idea nor the need to do it that way, but it looks kind unfamiliar for me... dunno why
Offline KaiHH

JGO Kernel


Medals: 486



« Reply #8 - Posted 2016-03-17 12:28:23 »

1  
new ArrayList<String>().add("abc").add("def")

This fluent interface style would already be possible today in your concrete example, had the ArrayList.add() method been designed to return the ArrayList<T> instead of whether the element was added to the list via a boolean.
You can perfectly design a new custom ArrayList that is capable of doing what you want:
1  
2  
3  
4  
5  
6  
7  
8  
9  
import java.util.ArrayList;
public class FluentStyleArrayList<T> extends ArrayList<T> {
    public FluentStyleArrayList<T> addFluent(T element) {
        add(element);
        return this;
    }
}
...
new FluentStyleArrayList<String>().addFluent("abc").addFluent("def")
Offline nsigma
« Reply #9 - Posted 2016-03-17 12:50:33 »

That will not work because the compiler does not know what type var would be if you use it as method parameter.

I know. I was being sarcastic!  Grin

Praxis LIVE - hybrid visual IDE for (live) creative coding
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matt_p
« Reply #10 - Posted 2016-03-17 13:11:24 »

That will not work because the compiler does not know what type var would be if you use it as method parameter.

I know. I was being sarcastic!  Grin

Oh, sorry... I see - should the "Joy!" indicate this? (Didn't get it though, got totally over my head, maybe because of my non-native-speaker-ness Wink) - so at least that is cleared up now

But yeah, I'm totally with you, its better to have it clear.
Offline Cero
« Reply #11 - Posted 2016-03-17 14:38:47 »

I'd rather have verbose and legible.

This.
Source code should be easily and quickly read and understood by humans.

Offline Roquen

JGO Kernel


Medals: 516



« Reply #12 - Posted 2016-03-18 09:21:39 »

Anytime a language adds a new feature there are ideally a number of points that should be considered, including (but far from limited to):

1) If it consumes syntax design space...is it worthwhile?
2) Does it fit the overall design space of the language?  Feature "A" can be a brilliant idea in language "B", but terrible for language "C".

Ignoring basic like this yield languages like Perl and C++.  C++ seems to spend a fair amount of it's time attempting to correct past mistakes.

And it doesn't help that a fair number of people working on compilers these days have lost touch with what they're really suppose to be doing.  What every compiler writer should know about programmers
Offline Coldstream24

JGO Ninja


Medals: 81
Projects: 1
Exp: 4 years


You can fill that void inside with programming, but you'll never return a value.


« Reply #13 - Posted 2016-03-18 09:41:08 »

@Roquen - i feel this is relevant

My website: http://www.onedropgames.com/
My soundcloud: http://www.soundcloud.com/coldstream24
Creator of the Morningside Engine, co-founder of Onedrop Games.
Offline Hydroque

JGO Coder


Medals: 25
Exp: 5 years


I'm always inspiring a good time.


« Reply #14 - Posted 2016-03-19 02:46:48 »

Quote
1  
2  
3  
4  
5  
6  
7  
8  
9  
import java.util.ArrayList;
public class FluentStyleArrayList<T> extends ArrayList<T> {
    public FluentStyleArrayList<T> addFluent(T element) {
        add(element);
        return this;
    }
}
...
new FluentStyleArrayList<String>().addFluent("abc").addFluent("def")

Wait...

1  
2  
3  
4  
5  
6  
7  
8  
9  
import java.util.ArrayList;
public class FluentStyleArrayList<T> extends ArrayList<T> {
    public FluentStyleArrayList<T> add(T element) {
        super.add(element);
        return this;
    }
}
...
new FluentStyleArrayList<String>().add("abc").add("def")


I have not a clue if this works.... never did this before.

You think I haven't been monitoring the chat? http://pastebin.java-gaming.org/c47d35366491fHere is a compilation <3
Offline princec

« JGO Spiffy Duke »


Medals: 982
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #15 - Posted 2016-03-19 09:31:01 »

I'm not a fan of fluent style stuff myself, though before my coffee I couldn't rant enough in a logical way to say exactly why yet...

Cas Smiley

Offline Riven
Administrator

« JGO Overlord »


Medals: 1327
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #16 - Posted 2016-03-19 16:40:18 »

I'm not a fan of fluent style stuff myself, though before my coffee I couldn't rant enough in a logical way to say exactly why yet...
Because it hides return-type changes. In real-world 'fluent' classes, not every method will return 'this'.

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

« JGO Spiffy Duke »


Medals: 982
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #17 - Posted 2016-03-19 16:52:13 »

Ah yes, that was it. And it looks daft.

Cas Smiley

Offline nsigma
« Reply #18 - Posted 2016-03-20 10:50:42 »

I'm not a fan of fluent style stuff myself

You must really hate Java 8 then?!  Tongue

Have to say I really am a fan of this if done well.  To me it's the opposite issue to above - reducing verbosity increasing legibility.  And it's not like you have to use it anyway.

Mind you, the fluent stuff (or any method call) on the end of a constructor does look daft.  To each his own.  Wink

Praxis LIVE - hybrid visual IDE for (live) creative coding
Pages: [1]
  ignore  |  Print  
 
 

 
Ecumene (145 views)
2017-09-30 02:57:34

theagentd (213 views)
2017-09-26 18:23:31

cybrmynd (292 views)
2017-08-02 12:28:51

cybrmynd (284 views)
2017-08-02 12:19:43

cybrmynd (294 views)
2017-08-02 12:18:09

Sralse (287 views)
2017-07-25 17:13:48

Archive (965 views)
2017-04-27 17:45:51

buddyBro (1092 views)
2017-04-05 03:38:00

CopyableCougar4 (1663 views)
2017-03-24 15:39:42

theagentd (1424 views)
2017-03-24 15:32:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!