Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8279611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:23:36+00:00 2026-06-08T09:23:36+00:00

Consider the constant in the following Java snippet : public class ConsumerServiceTestFixture { private

  • 0

Consider the constant in the following Java snippet :

public class ConsumerServiceTestFixture {
    private ConsumerServiceTestFixture() {
        throw new AssertionError("This class should not be instantiated");
    }

    public static final String CUSTOMER_ID_NOT_INTEGER = "12345678901";
}

The constant CUSTOMER_ID_NOT_INTEGER above is used to store a String which cannot be converted into an Integer because it’s value is greater than Integer.MAX_VALUE.

This is not apparent from the name of the variable which conveys, at best, that the value is an ‘invalid’ customer_id. Nothing is conveyed about why the value is invalid.

One option would be to write a comment which says something like :

// Invalid since this number is greater than Integer.MAX_VALUE
public static final String CUSTOMER_ID_NOT_INTEGER = "12345678901"; 

However, if we had to write self-documenting code and not use comments, the only other option would be to make the variable name more descriptive. Something like :

public static final String CUSTOMER_ID_GREATER_THAN_INTEGER_MAX_VALUE = "12345678901"; 

But, with the above option I am not happy about the length of the variable name, specially if you consider the following snippet about optimal variable name length from Code Complete 2 :

Chapter 11. The Power of Variable Names

How would you suggest I balance the length of the variable name vs. code readability ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:23:37+00:00Added an answer on June 8, 2026 at 9:23 am

    If instead of a // comment you use a /** comment (that is, javadoc), when a programmer uses your constant from an IDE or looks at your javadoc, he will get a full explanations of all the pros and cons of such a design, why it was done this way etc..

    Unfortunately, you cannot name it “CUSTOMER_ID_THAT_IS_A_STRING_BECAUSE_IF_IT_WAS_AN_INT_IT_WOULD_BE_TOO_LARGE”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following: namespace MyNamespace{ class MyClass { public: // Public area private: //
Consider this code snippet: public static void main(String[] args) { int z1 = 0;
Consider the following interface in Java: public interface I { public final String KEY
Consider the following code : public class Main implements Vehicle, Car { public static
Consider this class diagram: Car has a constant max speed of 200 kph, and
Consider the following code: template <class x1, class x2 = int*> struct CoreTemplate {
Consider the following code: public interface A { public A another(); } public interface
Consider the following snippet of code: foreach (var setting in RequiredSettings) { try {
Consider the following code public static void method(String[] srgs){ try{ }catch(){ System.out.println(Hello World +
Consider the following method, public void Add(Enum key, object value); Since Enum is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.