This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 131708 - Introduce API for answer to Life, Universe and Everything
Summary: Introduce API for answer to Life, Universe and Everything
Status: VERIFIED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Andrei Badea
URL:
Keywords: API, API_REVIEW_FAST
Depends on:
Blocks:
 
Reported: 2008-04-01 12:40 UTC by Andrei Badea
Modified: 2008-12-22 13:58 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Proposed change (2.80 KB, text/plain)
2008-04-01 12:43 UTC, Andrei Badea
Details
Proposed change (update 1) (2.80 KB, text/plain)
2008-04-01 13:37 UTC, Andrei Badea
Details
Usages of the proposed change (4.61 KB, text/plain)
2008-04-01 15:05 UTC, Andrei Badea
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Badea 2008-04-01 12:40:21 UTC
Introduce API for answer to Life, Universe and Everything

In a couple of places in the IDE a value (any value) is needed, and some developers seem to prefer the number 42. Among
others:

core.output2/test/unit/src/org/netbeans/core/output2/WrappedTextViewTest.java
core.startup/test/unit/src/org/netbeans/core/startup/jars/library-src/pkg/subpkg/Something.java
java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathSupport.java

In order to minimize usage of magic numbers and encourage other people to use this value, I propose to introduce an API
for it.

Since I believe this change is simple and uncontroversial, I want to shorten the review process a bit and commit later
today.
Comment 1 Andrei Badea 2008-04-01 12:43:59 UTC
Created attachment 59475 [details]
Proposed change
Comment 2 Andrei Badea 2008-04-01 12:44:34 UTC
Please review.
Comment 3 Milos Kleint 2008-04-01 12:47:06 UTC
looks good.
Comment 4 Milan Kubec 2008-04-01 12:50:58 UTC
Well crafted API.
Comment 5 Lukas Hasik 2008-04-01 12:55:14 UTC
seems reasonable. Please, please, only for trunk.  The upcoming NB 6.1 is bug fixing release therefore it definitelly
doesn't need sofisticated features as this one.
Comment 6 Petr Hejl 2008-04-01 12:58:42 UTC
PH01: It is suspicious that the ANSWER_TO_LIFE_UNIVERSE_AND_EVERYTHING is rational (number).
PH02: apichanges.xml - Change introduces new field so description is probably wrong ("returns the answer").
Comment 7 Andrei Badea 2008-04-01 13:37:08 UTC
Re PH01: we must be compatible with the standard. And it seems the author of the standard has specifically ruled out
non-integers: http://en.wikipedia.org/wiki/Answer_to_Life%2C_the_Universe%2C_and_Everything

Re PH02: OK, I will attach an updated diff to explain it better.
Comment 8 Andrei Badea 2008-04-01 13:37:34 UTC
Created attachment 59481 [details]
Proposed change (update 1)
Comment 9 Antonin Nebuzelsky 2008-04-01 13:51:50 UTC
TN01: what is the level of stability of this API?

TN01: an advise - it is always good to use a new API immediately after it is introduced to make sure that it suits its
usecases...
Comment 10 Andrei Badea 2008-04-01 15:04:32 UTC
Re TN01: excellent question. The number 42 is a third-party API, and general wisdom teaches that you should not allow
third-party APIs to leak into your API. However, since the value took such a long time to compute, I hope we can
consider it stable. Therefore, I propose to make in an official API. In the unlikely event that the value should change
in the future, we can always introduce Utilities.ANSWER_TO_LIFE_UNIVERSE_AND_EVERYTHING_2 to satisfy the backward
compatibility requirements.

Re TN02: you are right. I will attach a diff with changes in the mentioned files. I discovered that the number 42 is
also used in the java.refactoring, albeit multiplied by a constant, so that usage should be modified too.
Comment 11 Andrei Badea 2008-04-01 15:05:27 UTC
Created attachment 59486 [details]
Usages of the proposed change
Comment 12 Jesse Glick 2008-04-01 15:37:23 UTC
Looks great but

[JG01] Please verify that you do not block EQ for 2.3667714e+17 msec (or more, on slower hardware) computing the answer.
Comment 13 rbalada 2008-04-01 16:22:11 UTC
[RB01]: Can we get API also for recomputing the answer, just in case Sustaining team would need to maintain it?
Comment 14 Jaroslav Tulach 2008-04-01 16:31:33 UTC
Yff Missing @since tag
Yfe As always, I am not glad that a new API pollutes already pretty polluted openide.util. Can't you create a new 
module for this new addition?
Comment 15 Maros Sandor 2008-04-01 16:33:49 UTC
I would think twice about making ANSWER_TO_LIFE_UNIVERSE_AND_EVERYTHING public.
Comment 16 Andrei Badea 2008-04-01 16:34:58 UTC
Re JG01: sure. I used the value as precomputed by the author of the standard. I hope the author got it right, since I
didn't have a Deep Thought to check.

Re RB01: definitely. I would need you to provide a Deep Thought and make sure JDK 7 is ported to it.
Comment 17 Andrei Badea 2008-04-01 17:28:08 UTC
Re Yff: how could I forget that? I will attach an updated version

Re Yfe: well, having a special module for the answer to Life, Universe and Everything is a very appealing idea. However,
I  am afraid that such a solution would hinder the adoption of the API. Users would not know about the new module and
would reinvent or copy-paste (flawed) algorithms to compute the value, which, as Jesse pointed out, could impact the
performance of the IDE. Or they would just use the value directly, which is wrong (usages of magic numbers are
discouraged). I therefore believe that the API can only benefit from being in such a prominent module.
Comment 18 Vitezslav Stejskal 2008-04-01 19:05:45 UTC
VS01: I think that we should consider creating a pluggable SPI for this to support Netbeans platform users from
different Universes where the answer could be different.
Comment 19 mcupa 2008-04-01 19:21:48 UTC
Gents, that's really great idea... I'm building plug-in for CRM system and it would be really useful to be able to check
if life, universe and everything is still stable and ok when exception and/or unpredicted input happens.

It would be ideal to have this API available in Java so I would be able to call this check prior to all methods.
Stability of the system is crucial to us and this could be nice solid base...
Comment 20 Andrei Badea 2008-04-02 08:54:47 UTC
Thank you all for your valuable comments. Integrated in changeset 000001042008.
Comment 21 Jesse Glick 2008-06-16 17:14:29 UTC
Thanks! Everything is much clearer now.
Comment 22 Lukas Hasik 2008-07-01 10:33:35 UTC
verified in M1. 
IDE is now much more life friendly than I've ever expected. Just my .42 $