Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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  
  Missing some C++ features in Java  (Read 3513 times)
0 Members and 1 Guest are viewing this topic.
Offline zingbat

Senior Member




Java games rock!


« Posted 2006-03-18 20:59:33 »

Im working in a C++ project now and i wish i could have some C++ features in Java.

It's nice to have sinonims of types using typedef . This is almost essential when working with templates.

Simplified constructor syntax: Vector x(1,2,3); instead of Vector x = new Vector(1,2,3);

Structured primitive data. Its a pain not having this is Java. Syntax would be simply:

@primitive class Vector { float x; float y }

Defines a final class whose methods are all final if exist.

No arrays bound checks:  @nocheck int[] x

Sure there would be problems but the Java VM could have an option to run some classes in unsafe mode by setting a security policy for these classes.

Operator overloading: Vector x,y; x * y  instead of x.multiply(y). It's dumb to use the word multiply or even worst mul if we can and should use the * operator.
 
Offline noblemaster

JGO Ninja


Medals: 19
Projects: 9


Age of Conquest makes your day!


« Reply #1 - Posted 2006-03-19 00:07:59 »

That's the cool thing about Java! You don't have a bloated list of features, that you don't really need.

How about adding automated garbage collection to C++? Another nice thing is the amazing number of libraries (all free and really easy to use) in Java! Cool are the automatic array bounds checks, so you are not stuck with error messages such as "Segmentation Fault" like in C++.

Not allowed as well are assembly istructions in Java such as (whatever that is):
1  
2  
3  
      asm ("int \$0x80\n"
               : "=a" (sys)
               : "0" (sys), "b" (parm) );



Offline arne

Senior Member




money is the worst drug- we should not let it rule


« Reply #2 - Posted 2006-03-19 00:33:49 »

such features might be nice for the programmer, but are a pain in the arse for everybody else, who want's to read and understand the code or even worse: trace bugs.

:: JOODE :: Xith3d :: OdeJava ::
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mr_Light

Senior Member




shiny.


« Reply #3 - Posted 2006-03-19 01:26:18 »

that and easier is quite relative, we use ide's these days not notepath, vi, vim or what not.

and if certain tooling would become better I'd hardly type at all.

operater overloading might look nice in the beginning but it backfires like a cannon.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline thiagosc

Senior Newbie





« Reply #4 - Posted 2006-03-19 03:13:04 »

I have yet to understand how adding "sinonyms" to classes would help. If I have a "HashMap<Node, Node>" would it be better to know right away that it's a HashMap than find something like "Arc"? What's "Arc"? Is it a class, I don't find it in any package!? Where is it defined? Oh wait, a very intelligent developer called a HashMap an Arc.

I think this is a bug not a feature. Once I confronted a Python developer about this, Python has something similar, he told me that the "IDE would facilitate things". That's funny.

When it comes to bash Java then IDEs don't count, comparing isolated features is ok. When things get ugly for them then the IDE matters! Smiley
Offline Mr_Light

Senior Member




shiny.


« Reply #5 - Posted 2006-03-19 03:37:23 »

err?

no wenn it comes to (over)shorting syntax, that and introducing multply ways of defining the samething, everything should be kept as simple as possible but not simpler.

not sure what you gettign at if a subclass is called something well thats the developers fault if it isn't clear upon choosing the name, document you classes etc. I'm probebly missing the point?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline thiagosc

Senior Newbie





« Reply #6 - Posted 2006-03-19 04:16:23 »

I didn't understand your text, sorry.

I was criticizing typedef and I think it's bad. The classes should have meaningful enough names and not need sinonyms.
Offline Mr_Light

Senior Member




shiny.


« Reply #7 - Posted 2006-03-19 04:59:10 »

oh, nm I see you where refering to somethign else the reference to ide's kinda confused me.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline zingbat

Senior Member




Java games rock!


« Reply #8 - Posted 2006-03-19 15:33:29 »

I didn't understand your text, sorry.

I was criticizing typedef and I think it's bad. The classes should have meaningful enough names and not need sinonyms.

The problem with using templates is that meaningful names usualy become very long and you can't allways avoid it:

Hashmap<Integer,Set<Pair<SomethingA extends Something,SomethingB extends Something>>

Now try to create a new object with this:

Hashmap<Integer,Set<Pair<SomethingA extends Something,SomethingB extends Something>>> x =
new Hashmap<Integer,Set<Pair<SomethingA extends Something,SomethingB extends Something>>>(arguments);

It's even worst when you have a factory method:

HashmapFactory<Integer,Set<Pair<SomethingA extends Something,SomethingB extends Something>>> xfactory =
HashmapFactory<Integer,Set<Pair<SomethingA extends Something,SomethingB extends Something>>>.getFactory();
Hashmap<Integer,Set<Pair<SomethingA extends Something,SomethingB extends Something>>> x = xfactory.getInstance();

It would be a lot easier to write:

Hashmap<Integer,Set<Pair<SomethingA extends Something,SomethingB extends Something>>> x();

For what i know theres no IDE that rewrites the syntax of a language so you still have a readbility problem.
Offline Mr_Light

Senior Member




shiny.


« Reply #9 - Posted 2006-03-19 17:59:09 »

wheres the problem here? the lengthy constructor or the lengthy classname/discription?

Hashmap<Integer,Set<Pair<? extends Something,? extends Something>>> is just long.
a shortcut constructor isn't really saving you from that.

I thought there was an artikel on onjava or something going about something like this:
1  
2  
3  
4  
5  
HashMap<Integer,Set<Pair<? extends Something,? extends Something>>> dataStructure = newDataStructure(2);

public <A,B> HashMap<Integer, Set<Pair<A,B>>> newDataStructure(int capacity) {
    return new HashMap<Integer,Set<Pair<A,B>>>(capacity);
}

came across it yesterday by accident, can't find it anymore.

I haven't yet found it annoying enough to spend time to figure out a more elegant way of tackleing the problem.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cylab

JGO Knight


Medals: 34



« Reply #10 - Posted 2006-03-19 18:26:22 »

I think there are really some c++ features that would be nice to have in java. I am not sure about the typedef, since you are rarely in the need of such complicated generics usages. My wishlist would mainly contain two things:

- operator overloadng (using math libraries without it is really a pain)
- real templates (the java generics stuff is really just useful for collections)

Thereare several other things like properties and structs I would also like to have, but the two above are the things I really miss the most.

Mathias - I Know What [you] Did Last Summer!
Offline zingbat

Senior Member




Java games rock!


« Reply #11 - Posted 2006-03-19 18:38:27 »

typedefs are more useful in C++ when you have to declare a long list of methods of  class that return a very long and hard to read type.

Quote
inside the class

public <A,B> HashMap<Integer, Set<Pair<A,B>>> method1(arguments)
{
    return new HashMap<Integer,Set<Pair<A,B>>>(capacity);
}
...
public <A,B> HashMap<Integer, Set<Pair<A,B>>> methodN(arguments)
{
    return new HashMap<Integer,Set<Pair<A,B>>>(capacity);
}

It's much easier to read (lets call it alias instead of typedef):

Quote
inside the class

alias BookCatalog = HashMap<Integer, Set<Pair<A,B>>>;

public BookCatalog method1(arguments)
{
    return new BookCatalog(capacity);
}
...
public BookCatalog methodN(arguments)
{
    return new BookCatalog(capacity);
}

After working with more than one oo programming language that provide type aliases i miss them in Java in situations like this. It's not a big deal but it makes coding easier just like operator overloading when well used of course.

Quote
- real templates (the java generics stuff is really just useful for collections)

I never understood very well why we can't have primitive values in templates. It would go realy well with primitive classes the whay i described them above. Sometimes i wish i could  build my own Java language compiler without all these limitations.
Offline cylab

JGO Knight


Medals: 34



« Reply #12 - Posted 2006-03-19 18:47:44 »

Quote
Sometimes i wish i could  build my own Java language compiler without all these limitations.
http://pizzacompiler.sourceforge.net/ Wink

Mathias - I Know What [you] Did Last Summer!
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #13 - Posted 2006-03-19 20:03:41 »

Quote
It would be a lot easier to write:

Hashmap<Integer,Set<Pair<SomethingA extends Something,SomethingB extends Something>>> x();

You invalidate all of your arguments when you make this statement.
Offline thiagosc

Senior Newbie





« Reply #14 - Posted 2006-03-19 20:46:13 »

- real templates (the java generics stuff is really just useful for collections)

Maybe I'm being "too creative" here but I think we can do more with Generics than Collections, for example:

I have an interface:

1  
2  
3  
public interface Handler<T extends Something> {
    void handle(T something);
}


Then create a class like:

1  
2  
3  
4  
5  
public CarHandler implements Handler<Car> {
    public void handle(Car car) {
      // do something.
   }
}


If I used an interface instead of Generics I wouldn't be able to access the fields and other methods not specified in the interface without a Cast, and then bad things could happen.


Offline Mr_Light

Senior Member




shiny.


« Reply #15 - Posted 2006-03-19 21:09:47 »

Genetrics are there for compile time type safety. there are not coupled with collections it's just that with collections it's evident why you would want type safety.

use Genetrics where you need type safety.


It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline cylab

JGO Knight


Medals: 34



« Reply #16 - Posted 2006-03-20 10:13:37 »

Genetrics are there for compile time type safety. there are not coupled with collections it's just that with collections it's evident why you would want type safety.

use Genetrics where you need type safety.

That's exactly the reason, why I criticized generics in my comments. They are nothing more than a type safety construct, which is a good thing, but mainly only useful for collections, since most other use cases are covered by inheritance in conjunction with interfaces. I was used to treat templates like... eh, well... templates Smiley. In c++ templates are more of a compiler macro definition. The restrictions of the java generics implementation does not allow for more advanced usages like for example mixins (Yes, there are some tricky ways to simulate mixin behaviour, but they are messy).

Mathias - I Know What [you] Did Last Summer!
Offline kaffiene
« Reply #17 - Posted 2006-03-22 22:22:35 »

Personally, I loathe Templates with a passion.  Code bloat, incomprehensible error messages, slow compilation... no thanks!  Not to mention that the STL (as useful as it is!) was designed by a twisted and deranged mind.  The fact that there are lots of C++ programmers who think that the STL is an example of good design is a sad commentary on C++ programmers :o).

Anyway, the bottom line is that if you prefer C++, use it!  Clearly, everyone here finds Java a better fit for their needs JUST AS IT IS :o)  If we all thought Templates were the be all and end all, we'd be using C++, right?

Offline zingbat

Senior Member




Java games rock!


« Reply #18 - Posted 2006-03-23 02:02:40 »

Anyway, the bottom line is that if you prefer C++, use it!

What does that have to do with what i wrote?

If we all thought Templates were the be all and end all, we'd be using C++, right?

Don't see the connection at all. Templates were copied from other languages and they existed long before C was ever invented.

Edit for correction: C was copied from other languages too.
Offline Mr_Light

Senior Member




shiny.


« Reply #19 - Posted 2006-03-23 12:04:34 »

the discovery qoute popped up in my head reading the reply.

"if change is good why test it?"
"if change is wrong where would we be today?"
etc.

anyways to get right on topic,
language changes: "language X has foo,  we need foo in language Y too!" now at this point I'm not for change or against it, the only thing I ask is why? and what? Why should it change, and what happence if  we don't  change it. How is a result of the 2 former conclusions. Now this sounds simple but as with most things that appear simple, it's not as straightforward as you would like it to be.

in this case for example "We need templates" the aswer at this point is no we absolutly do not need them, templates are a means to an end, and we don't know to what end we want to go where. (ClassCastException : problem expected but solution found, for the geeks.) In other words what do we want? "Templates!" uge ugem, In other what do we want to achieve? and why is solution x the way to go? Some might yell that here problem x is selfevident and that it's self evident what the solution would be. Perhaps but it's better to avoid guessing and to reflect. 90% of all conflicts are because of communication errors or rather the lack of communication.

Communication is like (unit) tests it might go fine without them or ....yeah....

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline cylab

JGO Knight


Medals: 34



« Reply #20 - Posted 2006-03-23 15:14:37 »

I don't think we _need_ any of the features pointed out in this thread, but it would be _nice_ having them. Nothing more, nothing less.

Mathias - I Know What [you] Did Last Summer!
Pages: [1]
  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.

xsi3rr4x (42 views)
2014-04-15 18:08:23

BurntPizza (38 views)
2014-04-15 03:46:01

UprightPath (54 views)
2014-04-14 17:39:50

UprightPath (36 views)
2014-04-14 17:35:47

Porlus (53 views)
2014-04-14 15:48:38

tom_mai78101 (75 views)
2014-04-10 04:04:31

BurntPizza (134 views)
2014-04-08 23:06:04

tom_mai78101 (234 views)
2014-04-05 13:34:39

trollwarrior1 (195 views)
2014-04-04 12:06:45

CJLetsGame (203 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!