Giter Club home page Giter Club logo

Comments (5)

thaaks avatar thaaks commented on August 21, 2024

Hmmmmmm ;-)
My opinion:

  1. in Java 7 you can switch on Strings,
  2. your approach does not allow to create alarm ids dynamically like you could do with Strings. With Strings I can define alarms using constructed or configured Strings and I can react on them in the trigger method. I don't need to already specify them in the code.
  3. The string comparison only occurs in the alarmTriggered event. So it is really reduced to the absolute minimum. It is also only necessary if you use more than one alarm per entity class.

So for the advantage of avoiding string comparisons I would give away a lot of flexibility. So I am not convinced right now ;-)

from marteengine.

nanodeath avatar nanodeath commented on August 21, 2024

Hmm, I think your first point is fairly moot (forcing users to upgrade to Java 7 would be a non-starter), but the others are certainly valid. Additionally, if the string is defined in the Java source (and not, say, in an XML file) you would actually be able to use the == operator instead of .equals() in the alarmTriggered line since it would be interned string comparisons...which would be faster. Probably not worth the risk of bugs that might introduce if the string is ever not interned, though ;)

I'll close this for now, but maybe the example can use .equals() instead of .equalsIgnoreCase()? Seems unnecessary...

from marteengine.

thaaks avatar thaaks commented on August 21, 2024

I mentioned Java 7 just to point out that you could do a switch instead of ugly "if else" chains as soon as Java 7 is available.
Using == for String comparison is indeed risky :-)
But your point regarding equalsIgnoreCase() is true - it is unnecessary.

But thanks for your input! It's just great to get feedback and see that some people are interested in our stuff!

from marteengine.

Gornova avatar Gornova commented on August 21, 2024

thanks for your input from me too! We need to think about this kind of topic, so thanks! :D

About topic, our java for now is Java6 :D and I'll remove equalsignorecase method from example :d Thanks!

from marteengine.

nanodeath avatar nanodeath commented on August 21, 2024

I'm all for creating a nicer API over minor performance gains (premature optimization blah blah), but I feel I had to speak out here. But as @thaaks points out, it really would be a miniscule performance gain.

The game I'm poking around with now isn't so far along that I couldn't switch over to ME (which I may still well do), but...I want to work on features, first! Though the idea of a core base class (Entity) struck me as such a good idea that I actually am incorporating that aspect into my game, and using annotations to drive other aspects (whether to try to render an entity, so far).

from marteengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.