Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

leap year related

 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marilyn reminded me about the difference between | | and | (resp & and &&) and used
if ( y400 | | ( y4 && ! y100 ) )
to check the boolean condition.
I reversed the order:
( y4 && ! y100 ) | | y400
because the chance on y4 being true and y100 being false is bigger then y400 beeing true, so (hi hi [giggling]) in most cases is probably a tiny fraction of a microsecond more effective.
I mean: This sort of optimization should be done only in heavily used parts of a program, where this sort of consideration is worhtwhile.
Conclusion: the difference between | and | | is mostly unimportant
isn't it?
I would like a 'harder' reason to distinguish these operations.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It is not the answer your question but yet another explanation
If we go your way , Every time you need to use a minimum of two operations( && and !) no matter what the result is is .... BUt if we go the instructors way the no. of operations is just one ...
Well in this case it might take just a micro second ... but the ultimate objective is to introduce new java programmars to effiecient Programming and this is just a way to start it ...
After all if you can not maintain simple optimization for simple programs how can you do the same for huge programs ?
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This sort of optimization should be done only in heavily used parts of a program, where this sort of consideration is worhtwhile.


IMHO, writing optimized code is a good state of mind to be in all the time. You don't always know when you are writing a specific section whether it will later prove to be processing-intensive or not. Why would you want to write less-optimized code on the assumption that it won't matter, when it only takes one more keystroke to write better code?
In my early days as a greenhorn doing the Cattle Drive assignments, I felt myself resisting the advice that came with nitpicking. I thought my own years of programming experience should count for something. I finally came to realize that it was all meant to help me be a better Java programmer, and that if I spent my energies in employing the suggested styles and techniques instead of trying to prove why my way was just as good, I came out way ahead.
 
I need a new interior decorator. This tiny ad just painted every room in my house purple.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic