• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Appropriate Assertion

 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is the above an appropriate use of assertions? Acc. to Whizlabs it is, but for me, a method is getting called which wouldn't be if assertions were disabled (the side-effect thing).

Or, is Whizlabs correct, only because the method does nothing "significant"?
[ October 07, 2006: Message edited by: Aniket Patil ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method is only called if assertions are enabled and an AssertionError is thrown. I think that we are meant to assume that the purpose of the message() method is just to produce an appropriate message for the AssertionError. It's hard to decide if it's good or bad in my opinion.

What is tabu is to call a method which changes the computational state of the program as part of the asserted clause (left of the colon).
[ October 07, 2006: Message edited by: Barry Gaunt ]
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit,
You are right that "Assertions are disabled by default" .
So During runtime of the code if they are not enabled then there wont be any output.
If assertions are enabled then the output will be an Assertion Error.
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even though this assert statement calls a method, it does not have any side effects - the method does not change the state of the class. All the variable values stay the same.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic