Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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] 3 4 5
  ignore  |  Print  
  Why java over other languages?  (Read 14190 times)
0 Members and 1 Guest are viewing this topic.
Offline Roquen
« Reply #30 - Posted 2013-01-30 18:13:39 »

@Spasi - tools.  Don't forget the tools.
Offline Spasi
« Reply #31 - Posted 2013-01-30 18:21:24 »

Why would you want to?  Good feature of Java if you ask me, and with code completion it's almost a non-issue.  I'll take easy to comprehend over quick to write any day!  Wink

Verbosity is good when it helps to express developer intent. In Java's case, there's so much verbosity that developer intent is actually hidden from all the stuff that goes around it. Getters/setters vs properties, @NotNull/@Nullable vs null-safety at the language level, wildcards in generics vs declaration-site variance, no smart casts, no pattern matching, no automatic delegation, no infix method calls, no named or default arguments. Even more verbosity is coming with type annotations in Java 8. If easy comprehension is the goal, then why do I have to read pages of Java code to understand a few lines? Not to mention that, more often than not, those pages would be in many different source files.

@Spasi - tools.  Don't forget the tools.

Of course, I wouldn't even bother with Java without the awesome IDEs we use.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #32 - Posted 2013-01-31 00:47:11 »

You can write verbose code in a terse language.  The converse is not true.  If your coding standards require 20 lines of code to do a simple map and filter, go do that.  I'll do it in one line.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

« JGO Spiffy Duke »


Medals: 435
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #33 - Posted 2013-01-31 10:40:43 »

Well, at least I'll know exactly what it is I've told the computer to do. The terseness stuff lets the computer figure out more exactly how to do things in its own way but I have on many occasions had to delve into what it thinks is best when something misbehaves.

Java is not really that verbose, compared to even C++ or C. It's a happy medium.

Cas Smiley

Offline Varkas
« Reply #34 - Posted 2013-01-31 11:38:03 »

Compared to Pascal and Modula, Java isn't a particularly verbose language.

I don't know how to put it right. But there seem to be personal preferences on information desnity in source code. Some people like a lot of information is small space, others like it more spread out. If I look at old code of mine, I find that my own preferences have changed from dense to sparse code.

I don't think it is a benfit or a problem of a language if it is more verbose or terse than another. People have different prefernces and will choose what fits them best. And while you cannot shorten "BEGIN ... END" very much, you can space out "{ ... }" if you want more space in your code.

I forgot to say it in my last "Why Java" posting: I like the fact that Java limits multiple inheritance to one implementation and many interfaces. This avoids a lot of problems that other languages have.

if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline Spasi
« Reply #35 - Posted 2013-01-31 12:43:41 »

but I have on many occasions had to delve into what it thinks is best when something misbehaves.

But there seem to be personal preferences on information desnity in source code. Some people like a lot of information is small space, others like it more spread out. If I look at old code of mine, I find that my own preferences have changed from dense to sparse code.

So if the goal is to be able to write code that clearly shows developer intent and you knew for a fact that the following pieces of code produce the same bytecode:

1  
2  
3  
4  
5  
6  
7  
8  
9  
// Without lambdas
button.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    System.out.println("Button pressed: " + e);
  }
});

// With lambdas
button.addActionListener(e -> System.out.println("Button pressed: " + e));

Which one would you prefer*?

Note that this a feature that's actually coming to Java real soon, but there are many other examples of Java verbosity that can be toned down without resorting to alien syntax or compromising performance.

Java is not really that verbose, compared to even C++ or C. It's a happy medium.

I think the most interesting comparisons come from other JVM languages, not C/C++.

* I know that quickly writing an ActionListener is one shortcut away in modern IDEs, but the real issue is reading code, not writing it.
Offline ReBirth
« Reply #36 - Posted 2013-01-31 13:52:42 »

Lambda is great, but I still prefer Java's original style for that.

Offline Varkas
« Reply #37 - Posted 2013-01-31 14:54:28 »

1  
2  
// With lambdas
button.addActionListener(e -> System.out.println("Button pressed: " + e));

Which one would you prefer*?

I prefer the original java syntax.

- the lambda introduces a new operator "->" which must be learned
- Also the "e -> " part of the expression is alien to Java. It seems to be sort of argument passing to a parameter which has the same name as the argument ... it's also somethign new, other parts of java don't work this way.

I must say I think it is very good that the syntax of java doesn't have a lot of operators (unlike C++). I'm not fond of adding a new operator, and with it, implicit arguments (or how that may be called).

The original Java code is longer (-> IDE, code completion), but uses standard java syntax, and fits seamless with the other elements of the language. Even if longer, it's more "Java" and IMO better.

Moreover, the -> operator is redundant and people will have two ways to write code. This nowhere makes code easier to read, because people must know both styles to understand other peoples code then. Admitted it's not that bad, but there is no reason to make things worse without need.




if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline BoBear2681

JGO Coder


Medals: 19



« Reply #38 - Posted 2013-01-31 16:30:09 »

- the lambda introduces a new operator "->" which must be learned
- Also the "e -> " part of the expression is alien to Java. It seems to be sort of argument passing to a parameter which has the same name as the argument ... it's also somethign new, other parts of java don't work this way.

But if Java 1.0 were shipped supporting lambdas and this syntax you'd think differently, as you'd be used to it.  Just because you have to learn new syntax doesn't mean Java suddenly becomes bloated or confusing.

If you were learning Java post-Java 8, and your education included lambdas, would you think "this one feature is just too confusing," or would you simply accept it and happily move on?
Offline Cero
« Reply #39 - Posted 2013-01-31 19:29:06 »

yeah the -> is creepy and new

but this
1  
2  
3  
4  
5  
button.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    System.out.println("Button pressed: " + e);
  }
});

is really an unholy mess for something so simple

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spasi
« Reply #40 - Posted 2013-01-31 19:57:11 »

The initial lambdas proposal used a fat arrow (=>), similar to most other languages that support closures. But it looks ugly when the lambda expression contains a comparison:

1  
2  
3  
4  
5  
// Fat
x => y <= x

// Thin
x -> y <= x

But honestly, if I pretended other languages didn't exist, the lack of a type on the e parameter is much creepier from a Java perspective. I'm glad no-one complained about that. Tongue
Offline gene9

Senior Devvie


Medals: 10



« Reply #41 - Posted 2013-01-31 20:38:16 »

Java is *way* more elegant and cleaner than C++ on many, many levels.

Java is often simpler from a tooling/debugging perspective than Scala. However, Scala is a much more elegant language and I would chose Scala over Java for certain tasks.

The Java community. Ultimately, you can generally do whatever you want in any language you want, but a big factor is the community around the tools. Python has an amazing community for science type work. Java has an amazing community for distributed computing, data-centric workflows, build tools, etc. Games and graphics are actually one of Java's weaker sides, but it is still what I would choose over C++.
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #42 - Posted 2013-01-31 20:51:26 »

I really like Java over other languages because it is a lot cleaner and easier to understand. Java definitely can be verbose depending on what tasks you want it to do. But what it lacks in code writing time, it makes up for in compile time. It rewards you a lot better for clean code than the other languages do (less bugs), and can hit more platforms at the same time.

I don't have a problem with lambdas. It adds an extra level of easiness for those who need access to it. I think it would be a lot more ridiculous if they enforced lambda's. What these remind me of is the ternary operator...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
int a = 0;

//normal code
if(a > 5)
     a = 0;
else
     a = 4;

//ternary
a = (a < 5) ? 0 : 4;


I would like to argue that it is one of the least used features of Computer Science, followed by the bit shifts (but that is just me). However, just because they are there, doesn't mean that Java all of a sudden is an unreadable mess. Yes, adding many of these might make your code unreadable, just like lambdas might. But, it isn't a bad thing, because you have the option of whether you want to use them or not.

So, in short, it doesn't really matter. If you think your code is unreadable, you can just swap in a more readable version. For those who want to use them, let them use the short hand method.

Offline Varkas
« Reply #43 - Posted 2013-01-31 21:00:36 »

If you were learning Java post-Java 8, and your education included lambdas, would you think "this one feature is just too confusing," or would you simply accept it and happily move on?

I can't honestly answer this, I was working with Java too long and I am a really late adopter to anything new.

I can say that I came from C/C++ to Java and the new use of -> would have felt very confusing. In C the -> is the dereference operator for pointers-to-structs.

I was happy that the *, ->, and . operators from C became . in Java, that was a notable simplification. Anyways, I guess it's already decided and I assume after a period of boycott, I'll finally have to use the -> operator when I must maintain or want to use code that was written by early adopters.

if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline Don Kiddick

Junior Devvie





« Reply #44 - Posted 2013-01-31 21:16:17 »

mature
free
great tools
simple (got less simple after generic wildcards)
established - large amount of tools & libraries that are mostly free.
familiar syntax, lakes it easy to learn.
You can run the same code on various problems.
It changes slowly (perhaps also a negative.). But IMO compared to micrsoft projects they change their mind all the time. e.g. bye bye winforms, bye byesilverlight.

Java hits a pretty sweet spot as a general programming language.

On the negative side, it's suffered from chronic underinvestment, particularly on the desktop.
it's overly verbose too.

It's interesting to see what comes next, will existing languages handle the proliferation better (e.g by adding functional constructs), or whether the 'more' functional languages win out.
Interesting times1

Offline nsigma
« Reply #45 - Posted 2013-02-01 00:13:49 »

So if the goal is to be able to write code that clearly shows developer intent and you knew for a fact that the following pieces of code produce the same bytecode:

1  
2  
3  
4  
5  
6  
7  
8  
9  
// Without lambdas
button.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    System.out.println("Button pressed: " + e);
  }
});

// With lambdas
button.addActionListener(e -> System.out.println("Button pressed: " + e));

Which one would you prefer*?

Except that those two alternatives will almost certainly not produce the same bytecode.  The interesting thing about lambdas is that they're not just syntactic sugar for inner classes (eg. use of invokedynamic), with potential for performance improvement as well as being less verbose.

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline Best Username Ever

Junior Devvie





« Reply #46 - Posted 2013-02-01 00:26:02 »

So if the goal is to be able to write code that clearly shows developer intent and you knew for a fact that the following pieces of code produce the same bytecode:

1  
2  
3  
4  
5  
6  
7  
8  
9  
// Without lambdas
button.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    System.out.println("Button pressed: " + e);
  }
});

// With lambdas
button.addActionListener(e -> System.out.println("Button pressed: " + e));

Which one would you prefer*?

The first is easier to read. If you're trained to recognize indents you can "read" it in one glance. For the second one, I have to scan the screen horizontally and let my eyes stop in 3 places. It would be worse with more than one line. Both are poor choices. The reason I use Java is because I can determine the function of a block of code in one second just be looking at the structure or quickly scanning over it and can hunt down the code I am looking for in two seconds. Defining event listener methods in the same place they're used means that, if I am looking for the initialization, I have to find it between irrelevant code for various event listener methods or, if I am looking for the implementation of the methods, I have to find it between irrelevant code in some constructor or initializer function.

Here is an alternative that is much easier to read.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #47 - Posted 2013-02-01 01:36:05 »

Good grief this is turning into one of those threads again.   Roll Eyes

Offline ReBirth
« Reply #48 - Posted 2013-02-01 01:56:22 »

Java VS Lambda, start! *lifts spear*

Offline Best Username Ever

Junior Devvie





« Reply #49 - Posted 2013-02-01 05:37:15 »

A wild ThisLanguageUsesTheWrongAssignmentSymbol appeared. Fight, Switch, Item, or Run?
Offline Roquen
« Reply #50 - Posted 2013-02-01 06:53:24 »

@sproingie: same old problem.  Most programmers have only been exposed to one kind of language.  C++/C#/Java et al. are all hammers...they only seem significantly different to people who think all languages are hammers.
Offline princec

« JGO Spiffy Duke »


Medals: 435
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #51 - Posted 2013-02-01 11:24:11 »

Nothing wrong with hammers if nearly all your problems are nails  persecutioncomplex

Cas Smiley

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #52 - Posted 2013-02-01 13:02:38 »

1  
2  
// With lambdas
button.addActionListener(e -> System.out.println("Button pressed: " + e));


My main issue with this is that I have to guess what the type of 'e' is.
I really hate it when a language hides important stuff from me.

Offline Roquen
« Reply #53 - Posted 2013-02-01 13:23:48 »

@Cas: sure, but my point being it's hard to talk to hammer folks about hammer's with "that thingy that pulls out nails" if they never seen one...much less why one might want a saw from time to time.
@erikd: mouse-hover (assuming you somehow don't know off the top of your head)...you mean guessing like that? Smiley
Offline Cero
« Reply #54 - Posted 2013-02-01 13:35:22 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
int a = 0;

//normal code
if(a > 5)
     a = 0;
else
     a = 4;

//ternary
a = (a < 5) ? 0 : 4;


Yeah see: I would never do the short form, or ONLY in black boxed algorithms.
I think its fine if people like and use it; I however think its very hard to ready for a human, and I dont mind more lines just to make it clear... to humans. Reading code is really hard as a human D:


1  
2  
// With lambdas
button.addActionListener(e -> System.out.println("Button pressed: " + e));


My main issue with this is that I have to guess what the type of 'e' is.
I really hate it when a language hides important stuff from me.
I agree, its not perfect; You shouldn't have to guess.

Offline princec

« JGO Spiffy Duke »


Medals: 435
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #55 - Posted 2013-02-01 13:42:49 »

er, doesn't e have to be an ActionListener, that being the method sig? And the thing is you don't need to know it anyway, the whole idea is that it's completely unnecessary to even know...

(btw I quite like lambda! I just want to see it being used in anger for a while to get a feel for it all)

Cas Smiley

Offline Spasi
« Reply #56 - Posted 2013-02-01 14:08:25 »

No, e is an ActionEvent, the argument of the actionPerformed method of ActionListener. The lambda expression makes the method itself and the inner class instantiation go away.

Btw, lambdas allow an explicit type, so you could write it as:

1  
2  
3  
4  
5  
button.addActionListener((ActionEvent e) -> System.out.println("Button pressed: " + e));
// or
button.addActionListener((ActionEvent e) -> {
    System.out.println("Button pressed: " + e))
});;

This is a good example of a language feature that allows you to be more explicit and less dense if you wish so. The problem (imho) is when you can't do the opposite.

Except that those two alternatives will almost certainly not produce the same bytecode.  The interesting thing about lambdas is that they're not just syntactic sugar for inner classes (eg. use of invokedynamic), with potential for performance improvement as well as being less verbose.

Indeed, it compiles down to indy in the current JDK 8 builds. I should have said that, at runtime, it compiles down to the same-thing in the worst case scenario (if the JVM can't use a method handle and creates an instance instead).
Offline princec

« JGO Spiffy Duke »


Medals: 435
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #57 - Posted 2013-02-01 14:17:29 »

With the new type inferencing stuff in Java being introduced to make lambda easier, I wonder if it is yet possible to do
1  
2  
3  
4  
Object s = "some string";
String blah = s; // Type cast is implicit
CharSequence cs = s; // likewise
Rectange r = blah; // but this cannot succeed so compiler error thrown as usual

and if not why not?

Cas Smiley

Offline nsigma
« Reply #58 - Posted 2013-02-01 14:32:29 »

Except that those two alternatives will almost certainly not produce the same bytecode.  The interesting thing about lambdas is that they're not just syntactic sugar for inner classes (eg. use of invokedynamic), with potential for performance improvement as well as being less verbose.

Indeed, it compiles down to indy in the current JDK 8 builds. I should have said that, at runtime, it compiles down to the same-thing in the worst case scenario (if the JVM can't use a method handle and creates an instance instead).

Yes, I think a lot of people are missing the distinction, and think

the -> operator is redundant and people will have two ways to write code.

whereas because lambdas aren't classes (or instantiated objects in the majority of cases) there's the potential for (significant?) performance improvement rather than just being less verbose.  That missing "new" is important!  I can take or leave the ActionListener example - it's the collection transformation, parallelization uses, etc. where this gets interesting.

Nothing wrong with hammers if nearly all your problems are nails  persecutioncomplex

Sometimes you've got so many nails, a nailgun will stop your arm falling off!   Wink

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline Spasi
« Reply #59 - Posted 2013-02-01 14:34:03 »

and if not why not?

Because it's not really type inference. The compiler just lets you omit information that's already there.

Real type inference would require extensive code analysis at compile time, which would slow down javac. Imagine a condition or loop before the assignment to blah that assigns something other than a String to s. Also, it wouldn't offer much benefit without a new val/var keyword (or C++11's auto).
Pages: 1 [2] 3 4 5
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!