Comment On Exceptional Singleton

Balázs Szabó worked in a large company maintaining a few modules within a huge J2EE system. The system was notorious for its complete lack of error handling, providing users (and developers) with a simple message of failure: [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Exceptional Singleton

2006-02-07 14:18 • by HelluvaEngineer
You see, you can use a singleton model for every class!

Re: Exceptional Singleton

2006-02-07 14:20 • by pbounaix

yeah i mean, who needs an exception stack trace, right?


 


just make everything static. imagine the resources you save when you dont instantiate anything!

Re: Exceptional Singleton

2006-02-07 14:22 • by ObySamKenoby
59332 in reply to 59330
Anonymous:
You see, you can use a singleton model for every class!


Yes, and starting your brain before doing something like that could be a good thing. (NB: it's a continuation of your statement, not an offence)

Re: Exceptional Singleton

2006-02-07 14:22 • by Thiago
59333 in reply to 59330
this wtf makes me remember of this famous donald knuth quote: "Premature optimization is the root of all evil (or at least most of it) in programming."

Re: Exceptional Singleton

2006-02-07 14:24 • by Single Ton
How can they be an architecture team if they don't use patterns?

Re: Exceptional Singleton

2006-02-07 14:25 • by anonymous_
"some very error messages"?

as opposed to only "some error messages"

Ok, so we have..

2006-02-07 14:26 • by a0a
- lack of error/exception handling..

- no propper log/debug system..

- no test framework..

- *huge* j2EE systems probably have huge management and architecture overhead, and very small development teams..



.. and I just have the feeling that the application had some performance issues because of the high-traffic?



I wonder if there is actually J2EE stuff which works for these *huge* applications..







Re: Exceptional Singleton

2006-02-07 14:26 • by Sean
This is proof that singletons are like crack.  Dangerous if not used properly.

Re: Exceptional Singleton

2006-02-07 14:28 • by versatilia
59338 in reply to 59331
pbounaix:

yeah i mean, who needs an exception stack trace, right?






Don't get me started on those things... My eyes bleed every time I see
a production system (read: public website) throw up pages and pages of
stack trace when all you want is a user-friendly error message.



I'm beginning to think exception handling is last on the 'to do' list of java programmers.



As for tomcat fans and their insistence that a dual 1.5Ghz CPU with 2GB
DDR is just not enough to handle their 100 user website...



/troll

Re: Exceptional Singleton

2006-02-07 14:28 • by JohnO

Do you really want to throw an exception when a user fails to enter the right username or password?  Hardly exceptional with my users.


If said yes to 1 and you were creating your own exception class for it, would you call it "DataNotFoundException?"  How about AuthenticationFailureException?  Or LoginFailureException?


This is just another example of developers wasting too much time trying to "properly" handle exceptions and ending up with a worse result than if they had done nothing at all.

Re: Exceptional Singleton

2006-02-07 14:29 • by Xargon
Alex Papadimoulis:

An unexpected exception occurred. Please try again.

I've always wondered: what would an "expected exception" be, and would I be told if I encountered one?

Re: Exceptional Singleton

2006-02-07 14:32 • by BlackTigerX
ya'll know that the real WTF is using java for such application in the first place [:D]

Re: Exceptional Singleton

2006-02-07 14:37 • by HelluvaEngineer
59342 in reply to 59332
ObySamKenoby:
Anonymous:
You see, you can use a singleton model for every class!


Yes,
and starting your brain before doing something like that could be a
good thing. (NB: it's a continuation of your statement, not an offence)




Hmmm...come to think of it, they should implement a new Session object this way.

Re: Exceptional Singleton

2006-02-07 14:38 • by DiamondDave
59343 in reply to 59334
Anonymous:
How can they be an architecture team if they don't use patterns?




They just mis-use them....

Re: Exceptional Singleton

2006-02-07 14:39 • by Rain dog
59344 in reply to 59340
Xargon:
Alex Papadimoulis:

An unexpected exception occurred. Please try again.

I've always wondered: what would an "expected exception" be, and would I be told if I encountered one?


Those are generally every exception handled in Java or C#. It's expected that those throw exceptions.

Re: Exceptional Singleton

2006-02-07 14:44 • by mikeyd
59345 in reply to 59340
I've used exceptions to break out of a bunch of inner functions while returning a result, and so of course you wouldn't tell the user, it's expected.

Re: Exceptional Singleton

2006-02-07 14:44 • by Shadow_x99
59346 in reply to 59341
What would you use as a Web Development Platform?

ASP?

ASP.NET?

PHP4?

PHP5?

Perl?

Ruby?

Plain HTML with some AJAX with a SOAP Server?





Re: Exceptional Singleton

2006-02-07 14:49 • by .*
59348 in reply to 59346
Anonymous:
What would you use as a Web Development Platform?

ASP?

ASP.NET?

PHP4?

PHP5?

Perl?

Ruby?

Plain HTML with some AJAX with a SOAP Server?






Python, of course. Maybe if this forum was coded in Python instead of ASP it would work without Javascript.

Re: Exceptional Singleton

2006-02-07 14:50 • by ferrengi
59349 in reply to 59340
Alex Papadimoulis:

An unexpected exception occurred. Please try again.


This is like saying: "We expect to have certain exceptions happen on a regular basis (which makes one start to think, gee, if I expect this to happen, it isn't really an exception is it?) however, you just did something which caused another type of error which was totally unexpected and the application is not designed to handle it. I guess it's not your day today but maybe if you try again in a few minutes, your luck will be in and it will work!"


Re: Exceptional Singleton

2006-02-07 15:01 • by chrismcb
59350 in reply to 59340
Xargon:
Alex Papadimoulis:


An unexpected exception occurred. Please try again.


I've always wondered: what would an "expected exception" be, and would I be told if I encountered one?


invalid username/password

Re: Exceptional Singleton

2006-02-07 15:04 • by Maurits
59351 in reply to 59345
Anonymous:
I've used exceptions to break out of a bunch of inner functions while returning a result, and so of course you wouldn't tell the user, it's expected.


Exceptions aren't particularly fast.

Re: Exceptional Singleton

2006-02-07 15:24 • by masklinn
Alex Papadimoulis:
DataNotFoundException.getInstance().setMessage(errMsg);

throw DataNotFoundException.getInstance();

... and, as one might expect, DataNotFoundException was implemented as a singleton, as were all other exception classes. A rather interesting choice for what was a high-traffic J2EE web application in a multithreaded environment ...


Wouldn't that be an example of the famed Simpleton Pattern? (the 5th Cremational Resign Pattern)


Anonymous:
What would you use as a Web Development Platform?

ASP?

ASP.NET?

PHP4?

PHP5?

Perl?

Ruby?

Plain HTML with some AJAX with a SOAP Server?





Ruby/RoR or Python/Django (or maybe Python/Turbogears if you prefer, I'd go with Django though).


And if you want to toy with Ajaxy stuff, Prototype, MochiKit or Dojo (I think Django bundles Dojo, not sure though)


Not PHP for sure (too bothersome to keep clean), no fscking way I'd use Perl, and I don't know ASP nor ASP.Net.


So either RoR or Django, depending on the language you prefer (Ruby or Python).


There are some differences between the RoR and the Django "philosophies" (ways of life) that may also play a role in your choice, but... that's an other issue

Re: Exceptional Singleton

2006-02-07 15:26 • by giannis
59354 in reply to 59348
Anonymous:
Anonymous:
What would you use as a Web Development Platform?

ASP?

ASP.NET?

PHP4?

PHP5?

Perl?

Ruby?

Plain HTML with some AJAX with a SOAP Server?






Python, of course. Maybe if this forum was coded in Python instead of ASP it would work without Javascript.


ASP is not a programming language.

Re: Exceptional Singleton

2006-02-07 15:32 • by SeekerDarksteel
59355 in reply to 59346

Anonymous:
What would you use as a Web Development Platform?
ASP?
ASP.NET?
PHP4?
PHP5?
Perl?
Ruby?
Plain HTML with some AJAX with a SOAP Server?



 


Fortran.net.  That way everyone else I work with would actually have a shot at understanding how these newfangled webthingamajigs are programmed.

Re: Exceptional Singleton

2006-02-07 15:32 • by anon
Obviously the following pattern is required in this situation:

DataNotFoundException.getInstance().setMessage(errMsg);
DataNotFoundException.getInstance().setMessage(errMsg);
DataNotFoundException.getInstance().setMessage(errMsg);
throw DataNotFoundException.getInstance();




Re: Exceptional Singleton

2006-02-07 15:34 • by anon
59357 in reply to 59356
It totally cut out the url I tacked on.  See the forum posting "Ask Thrice. . ." if you don't get it. . .

Re: Exceptional Singleton

2006-02-07 15:42 • by Djinn
59358 in reply to 59345
Anonymous:
I've used exceptions to break out of a bunch of inner functions while returning a result, and so of course you wouldn't tell the user, it's expected.


You bastard.

[ unrelated ]
Just as with becoming a programmer in general, you should have to get a license to use design patterns. You get a license for driving, guns, and hunting, because we don't want people mishandling these things and getting hurt. Same principle here.

Re: Exceptional Singleton

2006-02-07 15:46 • by masklinn
59361 in reply to 59355
SeekerDarksteel:

Anonymous:
What would you use as a Web Development Platform?
ASP?
ASP.NET?
PHP4?
PHP5?
Perl?
Ruby?
Plain HTML with some AJAX with a SOAP Server?



 


Fortran.net.  That way everyone else I work with would actually have a shot at understanding how these newfangled webthingamajigs are programmed.


Fortran.Net is for the weaklings, Real Programmers use CGI/Fortran (or CGI/ASM if you prefer).

Re: Exceptional Singleton

2006-02-07 15:48 • by ObySamKenoby
59362 in reply to 59350
chrismcb:
Xargon:
Alex Papadimoulis:


An unexpected exception occurred. Please try again.


I've always wondered: what would an "expected exception" be, and would I be told if I encountered one?


invalid username/password



This shouldn't be an exception - it's something that you expect to happen. An exception is that - an exception, something that CAN happen but is not intended to happen (required files not found etc...). You should never use exceptions to handle your software flow, just to manage something wrong that can be corrected - automatically or not (ie - database not availableand so on...)

Re: Exceptional Singleton

2006-02-07 16:09 • by OneFactor
59363 in reply to 59358

Djinn:
Anonymous:
I've used exceptions to break out of a bunch of inner functions while returning a result, and so of course you wouldn't tell the user, it's expected.


You bastard.

[ unrelated ]
Just as with becoming a programmer in general, you should have to get a license to use design patterns. You get a license for driving, guns, and hunting, because we don't want people mishandling these things and getting hurt. Same principle here.


I dunno, whoever they dug up to teach the course would probably make it worse...


Imagine if you will, the next attempt at dealing with the singleton databaseexception. A flyweight-cache so as to share common message instances, a factory to create the right style of database exception, coupled with the option to choose one's factory at runtime via a prototype, and then the database exceptions could use a template pattern instead of messages, an observer pattern to decouple logging the databaseexceptions, and a swarm of decorators to allow these exceptions to wrap on top of each other.

Re: Exceptional Singleton

2006-02-07 16:12 • by nobody
Data Not Found is Data Not Found! No need to be picky about small details like the actual message sendt back. In fact, these users should just be happy that they didn't get a File Not Found, because, as everybody know, that is the same as 'false', which in turn is the same as '0', which is an artifact from C that means isTrue("trouble")=="paula", which will show you it's brillancy with a server-side seg. fault.

Sincerely,

![pi] approved.

Re: Exceptional Singleton

2006-02-07 16:13 • by JoeyLemur
59365 in reply to 59361
masklinn:

Fortran.Net is for the weaklings, Real Programmers use CGI/Fortran (or CGI/ASM if you prefer).



Nonsense.  Real programmers use Verilog on Rails.  Compiling means programming an FPGA!

Re: Exceptional Singleton

2006-02-07 16:17 • by mrsticks1982
59366 in reply to 59362
ObySamKenoby:
chrismcb:
Xargon:
Alex Papadimoulis:


An unexpected exception occurred. Please try again.


I've always wondered: what would an "expected exception" be, and would I be told if I encountered one?


invalid username/password




This shouldn't be an exception - it's something that you expect to happen. An exception is that - an exception, something that CAN happen but is not intended to happen (required files not found etc...). You should never use exceptions to handle your software flow, just to manage something wrong that can be corrected - automatically or not (ie - database not availableand so on...)


 


there is always one who thinks they are so smart!!

Web Development Platform

2006-02-07 16:22 • by Brian White
59367 in reply to 59354
Neither ASP nor ASP.Net are programming languages.  That's true.  That's also irrelevant.  The question was which would you use as a web development pattern.  Both ASP and ASP.Net are web development platforms.  Both can be implemented with multiple different languages.  ASP can be done in either VBScript or JScript natively, and there were other plugins to allow other languages, I'm pretty sure perl was one.  ASP.Net can be done in VB.net, C#, and JScript.net natively, and in others using plugins, including Perl, Python, and even (god help me) COBOL.net.

Re: Exceptional Singleton

2006-02-07 16:31 • by Satanicpuppy
59368 in reply to 59338
versatilia:
pbounaix:

yeah i mean, who needs an exception stack trace, right?






Don't get me started on those things... My eyes bleed every time I see
a production system (read: public website) throw up pages and pages of
stack trace when all you want is a user-friendly error message.



I'm beginning to think exception handling is last on the 'to do' list of java programmers.



As for tomcat fans and their insistence that a dual 1.5Ghz CPU with 2GB
DDR is just not enough to handle their 100 user website...



/troll


Are there really Tomcat "fans". I use Tomcat exclusively when I need to host JSP, and even I hate that piece of crap. The documentation is scanty, the configuration is weird, debugging other peoples setup is a nightmare. If there was something better, I'd use it in a second.

Re: Exceptional Singleton

2006-02-07 16:35 • by Satanicpuppy
59369 in reply to 59346
Anonymous:
What would you use as a Web Development Platform?

ASP?

ASP.NET?

PHP4?

PHP5?

Perl?

Ruby?

Plain HTML with some AJAX with a SOAP Server?






In order of preference:
Python,
*Pulls on flame retardant garmets*
Php5,
Perl,
*Removes flame retardant garmets*
Java,
C#.Net (I wouldn't let my dog code in ASP)

Re: Exceptional Singleton

2006-02-07 16:37 • by hash
59370 in reply to 59354
He never said it was, he said it was a web development platform... which it is... twat.

Re: Web Development Platform

2006-02-07 16:40 • by Shane
59371 in reply to 59367

Anonymous:
ASP.Net can be done in VB.net, C#, and JScript.net natively, and in others using plugins, including Perl, Python, and even (god help me) COBOL.net.


I'm pretty sure that if you're using COBOL.NET God has already abandoned you.  Go ahead and make a sign that reads "Now Entering Hell" and hang it just outside your cubicle entrance...

Re: Exceptional Singleton

2006-02-07 16:41 • by squirrel
While it required a collective blindness and stupidity to make error data code effectively global, I have to say that Java encourages a special kind of typed exception hell which ridiculous bookkeeping.

The nonsense is that you have to declare exception types that you may throw. This does not help design; no other language does this. You all know what you do when the compiler says that you're throwing something undeclared ... you use the IDE's refactor function to declare that you throw it. I hate fighting the compiler like that.

The easy way out of this, to make exceptions behave like other languages, is to only throw subclasses of RunTimeException (and hint! you can make your own!). You don't have to declare that you throw it then, you know !

How hard would it have been to change the exception types to RunTimeException, replace all the catch-drops, and voila! there would have been actual real error information.

But no. They hired a team of architects to build a solution that only Java suggests is necessary, and end up with something for a single thread environment. What's sad is that this is far and away the rule ...

Re: Exceptional Singleton

2006-02-07 16:50 • by Oli
The thought of rewriting an erroneous singleton-based application makes me cry blood.

Re: Exceptional Singleton

2006-02-07 16:59 • by kipthegreat
59374 in reply to 59369
Anonymous:
What would you use as a Web Development Platform?

ASP?

ASP.NET?

PHP4?

PHP5?

Perl?

Ruby?

Plain HTML with some AJAX with a SOAP Server?



I do all my HTMLs in ASM, on a processor I designed myself with parts from Radio Shack.  I don't trust high-level languages or processors.  Sure, it takes up my whole basement, runs at 0.000133MHz, and crashes after a good 15 minutes of processing, but if something breaks I don't have to ask M$ or Int€£ what's broken.

Re: Exceptional Singleton

2006-02-07 17:04 • by Djinn
59376 in reply to 59370
hash:
He never said it was, he said it was a web development platform... which it is... twat.


How long have you been dying to use that word on the internet?

Re: Exceptional Singleton

2006-02-07 17:14 • by Xepol
It didn't occur to anyone to check the code as they were adding in the exception handling?

Not sure which effort was more misguided here.

Re: Exceptional Singleton

2006-02-07 17:18 • by Cabbage
Alex Papadimoulis:
An unexpected exception occurred. Please try again.




Sound familiar? ("Something didn't quite work out ...")

Re: Exceptional Singleton

2006-02-07 17:20 • by Matt B
59380 in reply to 59353
masklinn:

Ruby/RoR or Python/Django (or maybe Python/Turbogears if you prefer, I'd go with Django though).


And if you want to toy with Ajaxy stuff, Prototype, MochiKit or Dojo (I think Django bundles Dojo, not sure though)


Not PHP for sure (too bothersome to keep clean), no fscking way I'd use Perl, and I don't know ASP nor ASP.Net.


So either RoR or Django, depending on the language you prefer (Ruby or Python).


There are some differences between the RoR and the Django "philosophies" (ways of life) that may also play a role in your choice, but... that's an other issue



this forum needs a huge rolleyes smiley

Re: Exceptional Singleton

2006-02-07 17:25 • by Casual WTF Viewer
59381 in reply to 59345

Anonymous:
I've used exceptions to break out of a bunch of inner functions while returning a result, and so of course you wouldn't tell the user, it's expected.


Arg...this might be one of the most prevelent things I see when reviewing code of recent CS graduates. It is NEVER appropriate to use exceptions to determine program flow. Throwing and catching an error take up significantly more resources than checking to see if you have met a condition. Int32.TryParse was created for a reason (C#; however, most languages have something similar). It is a poor solution no matter how you look at it. Please, do everyone who will interact with your code a favor - never use exceptions for process flow.

Enterprise Exceptions

2006-02-07 17:39 • by Andy
Sounds like a typical 'enterprise' solution: only works in an imaginary
world and is shot full of holes by aliens on a regular basis.

Re: Exceptional Singleton

2006-02-07 17:42 • by Matthew
59384 in reply to 59348

Anonymous:
Anonymous:
What would you use as a Web Development Platform?
ASP?
ASP.NET?
PHP4?
PHP5?
Perl?
Ruby?
Plain HTML with some AJAX with a SOAP Server?


Python, of course. Maybe if this forum was coded in Python instead of ASP it would work without Javascript.


Maybe. Or maybe you could read this instead:


http://en.wikipedia.org/wiki/Logical_fallacies

Re: Exceptional Singleton

2006-02-07 17:44 • by Matt
59385 in reply to 59381
Well, mostly I agree. However, in Python, using exceptions for such purposes is encouraged, and the core language itself has, for instance, a StopIteration exception. On the newsgroups, using exceptions for flow control is advocated by the senior pythonistas and the BDFL. So, as long as the language the OP was writing in was python, one might forgive him or her.

I gotta say, though, that the idea does make me a bit queasy (coming from a C++ background), but I'm otherwise quite fond of python, so I accept it.

-matt

Re: Exceptional Singleton

2006-02-07 17:45 • by Matt
59386 in reply to 59381
Er... lets try this again, with quoting:

Anonymous:

Anonymous:
I've used exceptions to break out of a bunch of inner functions while returning a result, and so of course you wouldn't tell the user, it's expected.


Arg...this might be one of the most prevelent things I see when reviewing code of recent CS graduates. It is NEVER appropriate to use exceptions to determine program flow. Throwing and catching an error take up significantly more resources than checking to see if you have met a condition. Int32.TryParse was created for a reason (C#; however, most languages have something similar). It is a poor solution no matter how you look at it. Please, do everyone who will interact with your code a favor - never use exceptions for process flow.



Well, mostly I agree. However, in Python, using exceptions for such purposes is encouraged, and the core language itself has, for instance, a StopIteration exception. On the newsgroups, using exceptions for flow control is advocated by the senior pythonistas and the BDFL. So, as long as the language the OP was writing in was python, one might forgive him or her.

I gotta say, though, that the idea does make me a bit queasy (coming from a C++ background), but I'm otherwise quite fond of python, so I accept it.

-matt

« PrevPage 1 | Page 2 | Page 3Next »

Add Comment