Sample

int-2fcc1106dc0f-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines53

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.8640–1; higher is more readable
Dorn0.4950–1; higher is more readable
Mi0.5910–1; higher is more readable
LLOC23Logical lines; fewer is more readable
DeepSeek V4 Pro17.330–20; mean of three runs
GPT-6.1 Sol17.670–20; mean of three runs
BTTF0.4330–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 default2(Class<T> typ) { checkNotNull(typ); if (typ.isPrimitive()) { if (typ == boolean.class) { return (T) Boolean.FALSE; } else if (typ == char.class) { return (T) Character.valueOf('\0'); } else if (typ == byte.class) { return (T) Byte.valueOf((byte) 0); } else if (typ == short.class) { return (T) Short.valueOf((short) 0); } else if (typ == int.class) { return (T) Integer.valueOf(0); } else if (typ == long.class) { return (T) Long.valueOf(0L); } else if (typ == float.class) { return (T) FLOAT_DEFAULT; } else if (typ == 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.1795.802−59.261
Source linesThe number of non-empty source lines.53+21.2
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.9−7.35

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

Score0.864

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.54−0.876
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.97.981+0.776
Indentation frequencyHow rapidly indentation changes from line to line.43+0.75
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.43−0.566
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.981−0.485
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.52.838+0.329
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.099−0.021

Intercept 0.07 + feature contributions = -0.022 (log-odds).
Score = sigmoid(-0.022) = 0.495.

Score0.591
Score23
Run 1

The code is highly readable with clear structure: a private constructor, constants for float/double defaults, and a well-documented single purpose method. The nested if-else chain for primitive types is somewhat deep but logically sequential and unavoidable without a switch or map. The Javadoc explains the behavior clearly, including edge cases for void and non-primitives. Action granularity is good—one operation per line. The method name 'default2' is slightly ambiguous (suggests a version suffix), which detracts from clarity. Suppression annotations are justified with comments. The method is concise, though the if-else chain could be flatter. Overall, intent is clear, flow is natural, and length is appropriate.

Run 2

The code is well-structured and readable. It uses clear constants for float and double defaults, has a single-purpose static method, and follows a logical, flat if-else chain. Naming is mostly clear (e.g., DOUBLE_DEFAULT), and the Javadoc explains intent well. Each return is on its own line, and action granularity is good. Minor issues: the method name 'default2' is ambiguous (likely a typo or leftover), and the long if-else chain, while flat, could be slightly more concise with a switch or map. Overall, the code is easy to follow with only small readability concerns.

Run 3

The code is highly readable with clear structure and organization. It uses a logical if-else chain for type checking, maintaining flat nesting (only two levels deep). Each branch performs a single action, aligning with one-action-per-line granularity. The intent is immediately clear: return default values for primitive types and null otherwise. The method is concise despite handling eight primitive types, avoiding unnecessary verbosity. Javadoc and annotations enhance clarity without cluttering the logic. Minor deductions: the `@SuppressWarnings` annotation is slightly distracting, and the method name `default2` is unusual, but overall the code is exceptionally readable.

Run 1

Code Structure: Logically organized utility class with constants and one focused method. Nesting: Only two levels, though the primitive guard adds modest indentation around the conditional chain. Clarity of intent: Documentation and explicit type comparisons clearly explain the behavior; however, default2 and typ are less descriptive names, and the documentation references type rather than typ. Code length: Compact overall; the repetitive branches are reasonable for explicit primitive handling. Action granularity: Each statement performs one clear action, with no compressed multi-action lines. Reading flow: Validation, primitive checks, and the null fallback follow a natural sequence. Minor naming and import-spacing issues prevent a perfect score.

Run 2

Code Structure: A focused utility class with logically grouped constants and a single straightforward method. Nesting: Only two conditional levels, though the outer primitive check adds slight nesting. Clarity of intent: Documentation and explicit type comparisons clearly explain the behavior; however, default2 and typ are less descriptive names, and the documentation references type instead of typ. Code length: Concise overall; the repetitive conditional chain is justified by distinct primitive types. Action granularity: Each statement performs one clear action, with no compressed multi-action lines. Reading flow: Validation, primitive handling, and the null fallback follow a natural sequence. Minor naming issues and the lengthy if/else chain slightly reduce readability.

Run 3

Code Structure: A focused utility class with logically organized constants and a single method. Nesting: Only two conditional levels, though the long else-if chain adds scanning effort. Clarity of intent: Documentation and explicit primitive comparisons clearly explain behavior; however, default2 and typ are less descriptive names, and the documentation references type rather than typ. Code length: Concise overall, with repetitive branches justified by distinct primitive types. Action granularity: Each statement performs one action, and returns are clearly separated. Reading flow: The sequence from null validation to primitive handling and the final null fallback is natural. Minor formatting issues, such as missing separation between the package and imports, slightly reduce readability.