Sample

int-725318bfed1b-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines61

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.870–1; higher is more readable
Dorn0.4640–1; higher is more readable
Mi0.5840–1; higher is more readable
LLOC31Logical lines; fewer is more readable
DeepSeek V4 Pro14.670–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.30–1; higher is more readable

Views

Source code

package com.google.common.base; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import org.jspecify.annotations.Nullable; /** * This class provides default values for all Java types, as defined by the JLS. * * @author Ben Yu * @since 1.0 */ @J2ktIncompatible @GwtIncompatible public final class Defaults { private Defaults() {} private static final Double DOUBLE_DEFAULT = 0d; private static final Float FLOAT_DEFAULT = 0f; /** * Returns the default value of {@code type} as defined by JLS --- {@code 0} for numbers, {@code * false} for {@code boolean} and {@code '\0'} for {@code char}. For non-primitive types and * {@code void}, {@code null} is returned. */ @SuppressWarnings({ "unchecked", "BooleanLiteral" // `(T) false` would produce an error }) public static <T> @Nullable T defaultValue(Class<T> type) { checkNotNull(type); if (type.isPrimitive()) { if (type == boolean.class) { return (T) Boolean.FALSE; } else if (type == char.class) { return (T) Character.valueOf('\0'); } else if (type == byte.class) { final int a = 1; final int b = -1; return (T) Byte.valueOf((byte) (a + b)); } else if (type == short.class) { final int c = 1; final int d = -1; return (T) Short.valueOf((short) (c + d)); } else if (type == int.class) { final int e = 1; final int f = -1; return (T) Integer.valueOf((e + f)); } else if (type == long.class) { final long g = 1L; final long h = -1L; return (T) Long.valueOf((g + h)); } else if (type == float.class) { return (T) FLOAT_DEFAULT; } else if (type == double.class) { return (T) DOUBLE_DEFAULT; } } return null; } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.2281.601−75.293
Source linesThe number of non-empty source lines.61+24.4
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.803−7.204

Intercept 8.87 + feature contributions = -49.227 (log-odds).
Score = sigmoid(-49.227) = 0.

Score0.87

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.62−1.159
Indentation frequencyHow rapidly indentation changes from line to line.51+1.027
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.97.952+0.776
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.51−0.749
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.97.968−0.484
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.60.879+0.441
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.104−0.065

Intercept 0.07 + feature contributions = -0.143 (log-odds).
Score = sigmoid(-0.143) = 0.464.

Score0.584
Score31
Run 1

The code is fairly readable with clear intent and logical structure, but has some stylistic issues that reduce its score. The structure is straightforward: a utility class with a single method. Nesting is moderate—the if-else chain for primitive types is acceptable but could be flattened with a switch or map. Clarity of intent is good: the Javadoc and method name make the purpose clear. Code length is reasonable but some parts are unnecessarily verbose, such as the artificial `final int a = 1; final int b = -1; return (a + b);` patterns, which obscure the simple goal of returning zero for numeric types. Action granularity is mostly one action per line, but those multi-line zero computations violate this principle. Reading flow is mostly natural, though the odd workarounds for byte/short/int/long defaults interrupt comprehension. Overall, the code is understandable but could be significantly cleaner with direct returns or a switch expression.

Run 2

The code is generally well-structured and readable, with a clear purpose and good documentation. However, there are some readability issues. The method uses a single multi-branch if-else chain for primitive types, which is not deeply nested but could be improved for clarity. The lines declaring local variables like 'final int a = 1; final int b = -1;' for each numeric type are unnecessarily verbose and arguably reduce readability compared to using a simple literal like (byte) 0. These extra lines also slightly impact the action granularity and reading flow. The class structure and naming are good, and the use of constants for float and double defaults is sensible. Overall, it is readable but not exemplary.

Run 3

The code is well-structured, with clear intent and logical organization. The class is final with a private constructor, annotations are used appropriately, and Javadoc explains the purpose. Nesting is shallow, and the method follows a simple if-else chain over primitive types, making the flow easy to follow. Action granularity is mostly one action per line, though local variables like 'a + b = 0' are unnecessary and slightly obscure intent. The method is concise overall, and the use of constants for float/double defaults improves readability. Minor deductions for redundant local variables and some casts that could be clearer, but overall the code is highly readable and maintainable.

Run 1

Code Structure: A focused utility class with a single method and logically ordered type checks. Nesting: Only two conditional levels, though the long else-if chain requires scanning. Clarity of intent: Documentation and method naming clearly explain the purpose, but variables a through h and arithmetic expressions obscure simple zero defaults. Code length: Mostly concise, with unnecessary variable declarations and calculations in four branches. Action granularity: Each declaration and return occupies its own line, making individual operations easy to follow. Reading flow: Consistent formatting and sequential primitive-type handling support natural reading, but the artificial arithmetic interrupts an otherwise straightforward pattern.

Run 2

Code Structure: A focused utility class with a logically organized primitive-type dispatch. Nesting: Only two conditional levels, although the long else-if chain adds scanning effort. Clarity of intent: Documentation and method naming clearly explain the purpose, but computing zero through pairs of vaguely named variables obscures otherwise straightforward returns. Code length: Mostly concise, with unnecessary declarations and arithmetic in the byte, short, int, and long branches. Action granularity: Each statement performs one action, making individual steps easy to follow. Reading flow: Type checks follow a predictable sequence and end with a clear null fallback; however, redundant arithmetic interrupts the flow and inconsistent handling of numeric defaults reduces uniformity.

Run 3

Code Structure: The utility class and single method are logically organized, with a straightforward type-dispatch chain. Nesting: Two conditional levels are manageable, though the primitive guard adds some indentation. Clarity of intent: Documentation, method naming, and explicit type checks clearly explain the purpose; however, variables a through h and arithmetic expressions obscure the simple intent of returning zero. Code length: Generally compact, but the unnecessary variable declarations and additions inflate four branches. Action granularity: Each statement performs one action, making individual steps easy to follow. Reading flow: The sequential type checks and final null return are predictable and natural, but the inconsistent treatment of numeric defaults interrupts the pattern and adds avoidable cognitive effort.