• Post Reply Bookmark Topic Watch Topic
  • New Topic

constructor is necessary ???  RSS feed

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a constructor doesn't have any code then should we remove it from the class ( will reduce number of line ) or not ( will save compiler's time )

Thanks .
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:
If a constructor doesn't have any code then should we remove it from the class ( will reduce number of line ) or not ( will save compiler's time )

Thanks .


A couple of lines would cetainly make no differnce. I suggest you not to worry for the constructor lines.

If you think that your compiler is too slow , you could consider downloading Jikes compiler from IBM Web Site.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there is no constructor defined, the compiler creates one since each class MUST provide for memory allocation and initialization. Making constructors fast has been the focus of MUCH effort by the language developers. Worry instead about excessive creation of objects by bad program design.
Bill
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still confuse ,
We should type such constructor or not ???


Thanks .
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:
[QB]still confuse ,
We should type such constructor or not ???


I have already posted , not to worry abt them. It doesn't matter if you have it or not.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for input .
is there no best practice for this ...

Thanks .
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:
thanks for input .
is there no best practice for this ...

Thanks .



The best practice is not to worry about such small things.
If you are not comfortbale, do not use those constructors.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I typically delete them when I spot them, but don't actively hunt them down. To me, code that doesn't serve a purpose only adds clutter and thereby reduces expressiveness.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Pradeep & Ilja ,
Now I got my answer .
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't worry too.

If I would, I would write some testcode, to compare compilationtime of explicit and implicit constructors.

Perhaps the explicit constructor is faster, because the missing of an ctor has to be determined, and the implicit ctor has to be generated by the machine?

Compile a few million times, and compare the durations.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!