• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Does Patterns comes with an opportunity cost of speed

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
What's your guys thought about patterns and speed? Some patterns triggered too many methods call, some load too many classes that increase your program's fooprint. How do we tell it is a pattern or anti-pattern?
Any good patterns for J2ME programming?
Thanks
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Frank Zheng:
How do we tell it is a pattern or anti-pattern?


Experience.
That's why books, like Bruce's are useful. You make yourself more aware of what works and doesn't work. But, really, I've only found that experience helps - reading books just increases your experience in the area.
Corey
 
Sheriff
Posts: 15501
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Frank Zheng:
What's your guys thought about patterns and speed? Some patterns triggered too many methods call, some load too many classes that increase your program's fooprint. How do we tell it is a pattern or anti-pattern?
Again, if it has a negative impact on your application, you might be dealing with an antipattern. However, a pattern description often includes the consequences, both positive and negative, of using it and you should factor those consequences into your decision to use the pattern. If the impact of the negative consequences outweigh those of the positive, then you should probably try to find another pattern or a variation of the original pattern.
This brings another question to mind: When normalizing a relational database design, you sometimes end up with inefficiencies. To improve efficiency, database designers sometimes will purposely denormalize the database design. I wonder if some software designers do similar "defactoring" and purposely deviate from a design pattern to improve efficiency.
OTOH, a good design often is the most efficient.
Any thoughts on this?
Junilu
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Junilu Lacar:
I wonder if some software designers do similar "defactoring" and purposely deviate from a design pattern to improve efficiency.


Not only to improve efficiency, but also to improve design. Patterns are like templates, imo. After you applied them by the book, you should start to vary them, to adapt them to your needs. After a while you will just use them rather unconsciously, not caring about wether you use them or not.


OTOH, a good design often is the most efficient.


And if not the most efficient, it will be the easiest to optimize...
 
Junilu Lacar
Sheriff
Posts: 15501
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:
After a while you will just use them rather unconsciously, not caring about wether you use them or not.
Ah yes, the Ri stage of learning...
 
Frank Zheng
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This brings another question to mind: When normalizing a relational database design, you sometimes end up with inefficiencies. To improve efficiency, database designers sometimes will purposely denormalize the database design. I wonder if some software designers do similar "defactoring" and purposely deviate from a design pattern to improve efficiency.


Yeah,That's why we somtimes not-patterning to do the ugly job for the badly need efficiency.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Junilu Lacar:
Ah yes, the Ri stage of learning...


Exactly! I just didn't find the link to http://c2.com/cgi/wiki?ThreeLevelsOfAudience, even though I searched especially for "three" in the page titles... :roll:
 
Frank Zheng
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So no patterns for J2ME so far?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Junilu Lacar:
I wonder if some software designers do similar "defactoring" and purposely deviate from a design pattern to improve efficiency.


Like Ilja said, patterns are like templates. In certain situations, a pattern might not function in the exact manner that you want it to. For example, let's say that you want to control the number of instances of a class, but you don't want just one. You wouldn't want to use a Singleton pattern exactly as it is, you'd make some slight variation to it. Even though I can't think of a decent example off the top of my head, I would imagine similar modifications could be made to some patterns in order to improve performance. Of course, most patterns are called patterns because they are about as well designed as possible.
There's my two cents,
Corey
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Of course, most patterns are called patterns because they are about as well designed as possible.


Most patterns are as well designed as possible if you want to do exactly the thing they were made for. They may not be so great if you want something different.
If you value speed over maintainability & flexibility, many of the GoF patterns are not what you'd want to use (an extra layer through a facade?). The fastest code is often ugly as hell. It might still be best design for your application, depending on the requirements.
 
Frank Zheng
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any J2ME people around here?
I am going to do some J2ME programming(First time, something about Midlet?) in our next project. Could anybody share any lights on how patterns for J2SE could servival in J2ME(a place speed and footprint be the critical part)?
Thanks
 
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This discussion applies to not just patterns but more general principles, like abstraction layers (although those are probably listed as patterns somewhere). Remember how you're suppose to layer your application, and isolate, and control it, and put in all sorts of indirection so everything is isolated from each other? Boy that can kill performance! This is why experienced programmers are valuable, becaus they know when to apply certain rules, when to bend them, and when to outright break them.
WRT J2ME, there are no J2ME specific patterns that I'm aware of. I can;t envision why any would be J2ME specific. Instead, simply remember that J2ME has constrained speed, memory, bandwith, screen real estate, etc. Choose patterns appropriately to work within these constraints. Obviously any pattern, like any engineering choice, makes a tradeoff, so you'll have to prioritize which of those factors you are trying to improve.
--Mark
 
Frank Zheng
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark.
Just one more question:
This is not specific to J2ME or J2SE. To help garbage collector a little bit, most experienced programmers usually explicitly set no-use object references to null. I am wondering is there any pattern aound this to help garbage collection.
I mean a good way to track unused, yet not referenced object. I hope this not sound unnecessary.
[ June 06, 2002: Message edited by: Frank Zheng ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Frank Zheng:
garbage collector a little bit, most experienced programmers usually explicitly set no-use object references to null. I am wondering is there any pattern aound this to help garbage collection.
I mean a good way to track unused, yet not referenced object. I hope this not sound unnecessary.


I don't know if this answers your question, and this seems to be deviating a bit from the topic at hand, but you might want to look into the java.lang.ref package. Using the classes within that package can help you gain a bit of control over your interaction with the garbage collector.
I hope that helps,
Corey
 
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well whether using or following a particlar patern would consume time and hamper performance and speed is a very ambigious statement.One needs to make a consioucs decision based on his requirement,but definately it should not be the case that just for the sake of using a MVC, or a Front Controller or any other pattern you sacrifice on speed and performance.As said earlier one needs to indulge in good design principles and write optimal code ..that's were mark pointed out "This is why experienced programmers are valuable, becaus they know when to apply certain rules, when to bend them, and when to outright break them."
Would like to ask Mark to throw some more light on this...
 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Frank Zheng:
This is not specific to J2ME or J2SE. To help garbage collector a little bit, most experienced programmers usually explicitly set no-use object references to null. I am wondering is there any pattern aound this to help garbage collection.
I mean a good way to track unused, yet not referenced object. I hope this not sound unnecessary.


First, remember then even when you set it to null, there's no garantee that it will be collected.
I seem to recall some type of reverse factory pattern, where you send an object to a special place to be destroyed. This object is then cleanly and safely deconstructed, e.g. if it has a DB connection, that connection is released and/or closed. It's late and I can't recall any more info about the pattern.
--Mark
 
Rishi Singh
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,
can we have some more info about the reverse factory pattern,any links, description, usage will do
 
Wouter Zelle
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I seem to recall some type of reverse factory pattern, where you send an object to a special place to be destroyed.


The trashcan pattern?
 
Frank Zheng
Ranch Hand
Posts: 76
 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Rishi Singh:
"This is why experienced programmers are valuable, becaus they know when to apply certain rules, when to bend them, and when to outright break them."
Would like to ask Mark to throw some more light on this...


Um, I'm not sure what to say? Basically if there were hard and fast rules, it would be automated. It's not unlike writing, or architecture (for buildings), a good writer or architect knows when the rules don't apply to a certain situation. This is true for most design work.
Do you have any specific questions? I might be able to give better answers to those.
--Mark
 
There is no "i" in denial. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic