Sample

int-5d719c330842-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines63

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6280–1; higher is more readable
Dorn0.4660–1; higher is more readable
Mi0.5960–1; higher is more readable
LLOC30Logical lines; fewer is more readable
DeepSeek V4 Pro8.670–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.420–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() { { int previousNumber = 0; int currentNumber = 1; for (int sequenceStep = 0; sequenceStep < 4; sequenceStep++) { int nextNumber = previousNumber + currentNumber; previousNumber = currentNumber; currentNumber = nextNumber; } } } 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) { return (T) Byte.valueOf((byte) 0); } else if (type == short.class) { return (T) Short.valueOf((short) 0); } else if (type == int.class) { return (T) Integer.valueOf(0); } else if (type == long.class) { return (T) Long.valueOf(0L); } 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.2118.174−69.9
Source linesThe number of non-empty source lines.63+25.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.904−7.357

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

Score0.628

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.64−1.23
Indentation frequencyHow rapidly indentation changes from line to line.53+1.096
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.53−0.795
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.96.406+0.751
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.984−0.485
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.62.778+0.468
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.098−0.011

Intercept 0.07 + feature contributions = -0.136 (log-odds).
Score = sigmoid(-0.136) = 0.466.

Score0.596
Score30
Run 1

The code has a clear structure with a private constructor, constants, and a well-documented public method. However, it contains a serious structural error: an extra nested block with a Fibonacci sequence calculation inside the constructor body, which is completely unrelated to the class purpose. This creates invalid syntax and severely hurts readability. The defaultValue method is flat and logically organized, with a clear if-else chain for primitive types, but the action granularity is inconsistent—multiple casts and returns share lines. The reading flow is mostly natural, but the stray block disrupts it. Clarity of intent is good in the method documentation and constant names. Code length is reasonable, though the if-else chain could be simplified with a switch or map. Overall, the unexpected constructor block makes the code confusing and undermines what would otherwise be fairly readable utility code.

Run 2

The code has a fatal structural flaw: a random Fibonacci sequence block is embedded inside the private constructor, breaking logical organization and reading flow. The actual `defaultValue` method uses a long if-else chain inside nested conditionals, which is repetitive and reduces clarity. There are stray extra braces, indicating tangled code. The method intent is somewhat clear but obscured by the lengthy primitive-type checks and unnecessary boxing for types with cached constants. Action granularity is okay in the method body but the closure braces are poor. Overall, the code is difficult to read and maintain due to the structural anomaly and verbose conditional logic.

Run 3

The code is generally clear and well-structured, with a logical class purpose and a straightforward if-else chain in defaultValue. However, there is a significant structural flaw: a stray, nonsensical block appears inside the private constructor, containing unrelated Fibonacci-like logic. This confuses intent and breaks reading flow. The if-else chain, while flat and easy to follow, is somewhat repetitive and could benefit from a switch or map. Method documentation is helpful, and variable names are clear. Overall readability is moderate—mostly understandable, but the misplaced block is a notable issue.

Run 1

Code Structure: The utility class, constants, and default-value method are logically organized, but the constructor contains an unrelated sequence calculation with poorly formatted braces. Nesting: The main method has manageable two-level nesting; the constructor adds an unnecessary nested block. Clarity of intent: Documentation, descriptive names, and explicit primitive-type checks make the main purpose clear, while the unused constructor calculation is distracting and unexplained. Code length: The type-dispatch chain is reasonably concise for its task, but the constructor adds needless lines. Action granularity: Statements generally perform one action per line, supporting easy scanning. Reading flow: The ordered checks and consistent return patterns read naturally, though the constructor's indentation and irrelevant logic interrupt an otherwise clean flow.

Run 2

Code Structure: The utility class and default-value method are logically organized, but the unrelated Fibonacci-style calculation in the private constructor disrupts cohesion. Nesting: The main method has modest nesting; the constructor adds an unnecessary block with poorly aligned braces. Clarity of intent: Documentation, descriptive names, and explicit type checks clearly communicate the main purpose, while the unused constructor calculation is unexplained. Code length: The type-specific branches are reasonably concise, but the constructor adds unnecessary code. Action granularity: Statements generally perform one action per line, making operations easy to follow. Reading flow: The primitive checks follow a predictable sequence and end naturally with null, but inconsistent constructor indentation and minimal spacing around imports interrupt the flow.

Run 3

Code Structure: The utility class and default-value method are logically organized, but the unrelated Fibonacci calculation in the private constructor disrupts cohesion. Nesting: The primitive check and conditional chain have manageable depth; the constructor adds an unnecessary nested block. Clarity of intent: Documentation, descriptive names, and explicit type comparisons clearly explain the main functionality, while the unused constructor calculation is unexplained. Code length: The type-handling chain is reasonably concise, but the constructor contains unnecessary code. Action granularity: Statements generally perform one action per line, making operations easy to follow. Reading flow: The main method follows a predictable sequence, but inconsistent constructor indentation and stray-looking braces interrupt the otherwise natural flow.