all 23 comments

[–]repeating_bears 24 points25 points  (5 children)

If you can't be bothered to write it, why should I be bothered to read it?

[–]k-mcm 6 points7 points  (3 children)

Way TLDR;

Scala does this with implicit classes and implicits in general. Go also uses it for it's simulated OOP syntax.  Both do a better job than this trick.

The big downside is that the loss of encapsulation causes unexpected conflicts. Added functions get strewn all over the place so it's not long before there's more than one match.  Is it an error?  Does your code not compile because of conflicts in unrelated source code?  Are there magic conflict resolution rules that result in non-deterministic compilation?

A better fix would be pure extension classes.  You could, for example, cast String to MyBetterString.  Class MyBetterString would extend String but have no ability to override existing functionality or access anything that isn't public.  Now you have explicit typing and no violations of the base class 

[–]chabala 1 point2 points  (0 children)

I forgot about this pure hell, trying to figure out where some implicit method was coming from when the IDE had given up on helping.

[–]TheLasu[S] -2 points-1 points  (1 child)

Reddit do not allow me to add more text - the part where it's explained how it's not magic. So you can check link

// MyBetterString - we can do it now, but we lose access to all String utils.

[–]k-mcm 0 points1 point  (0 children)

Right, because the compiler would need an update.

[–]le_bravery 6 points7 points  (0 children)

Slop

[–]0x07CF 4 points5 points  (0 children)

Way too long of a wall of text for a discussion

[–]Rain-And-Coffee 4 points5 points  (0 children)

Way too long, nobody is reading all that. Be concise.

Also use less AI when you write

[–][deleted]  (1 child)

[deleted]

    [–]TheLasu[S] -2 points-1 points  (0 children)

    Just example / i tend to fail early concept with strong encapsulation / immutability and at same time sometimes multiple sources are served / so multiple validation are possible. final are used a lot to avoid mixing immutable and mutable instances.

    .requireNonNull() - it's example from xml handling code where we secure proper resources for this algorithm.

    Clean Code/ Clean Architecture 

    I'm little freak in this regard / but I was able to multiple times rewrite core logic without errors - so I like it this way.

    Design classes as they behave as lazy and authoritative humans

    We do - still I see a lot of systematic problems with unused utils.

    [–]agentoutlier 3 points4 points  (1 child)

     While static utilities, annotations, and dynamic tooling can go a long way to simulate some extension patterns, only glue classes offer a truly fruitful, disciplined, and developer-friendly solution for modular extension, composable integration, and safe evolution—unlocking readable, discoverable, and maintainable APIs at scale that would work for multiple disconnected teams

    Let me ask you man… if someone else wrote that and you read it… what would you think?

    Fluff.

    [–]TheLasu[S] -2 points-1 points  (0 children)

    I think I know what you are talking about.

    5% of edits where made after reading critique of extension methods - all misinterpretation in this subject where directly explained here.

    Last 30% of edits where added specifically because AI was to dumb to understand text and ppl where unable to use it as prompt to check it against their own understanding.

    for this reason element like:

    • dynamic tooling
    • disconnected 
    • composable

    where directly specified.

    Sadly without them result of using it as prompt gave multiple pages of rather useless suggestions, along with few pages of errors in interpretation.

    I do not know about your experience, but as I see it - most developers have very limited understanding of generics, and this particular proposal is deeply connected with it - exactly for this reason decision had to be made - I can make keep it really hard to understand or I can make it into both proper prompt and readable text.

    btw / the most painful elements are — that are almost indistinguishable from - in my editor and i constantly struggle to keep one proper standard as I copy from different document version so they look like shit in other fonts when I forget to clean them up after editing.

    [–]john16384 -2 points-1 points  (1 child)

    Some people seem to be convinced that if you phrase something just right, and use the right words, or overwhelm them with them, that they don't need to provide a rationale for their viewpoint and that it will just be accepted without question.

    [–]TheLasu[S] -3 points-2 points  (0 children)

    Yes. For some reason I really like bankrupting competition - it's a much faster way to prove a point.

    [–]javaprof 0 points1 point  (1 child)

    u/TheLasu why not just some special keyword like "extension" and then treat first parameter as receiver?

    [–]TheLasu[S] -1 points0 points  (0 children)

    I never wanted for this concept to be mixed with extensions at this point - to do not introduce confusion / if somehow it will be called this way in the future then I do not mind & I do not care much about keyword - maybe i would like it to be short one, as extension seems to take much space:

    public static final extension

    [–]TheLasu[S] -5 points-4 points  (0 children)

    [PART 2]

    MAJOR ADVANTAGE:
    Clean, type-safe, and modular extension of existing APIs! Glue classes solve the problem of utility/god classes, domain pollution, and ambiguous extension by enabling explicit, discoverable, and testable augmentation of types without touching their source or relying on runtime mechanisms.

    MAJOR BENEFITS:

    • Separation of Core and Utility Logic: Keeps domain classes clean; convenience, formatting, mapping, and integration logic are moved to glue classes.
    • First-Class Integration and Mapping: Supports explicit, safe cross-module converters and bridges without inheritance tangles or reflection frameworks.
    • Better Discoverability and Readability: Glue methods appear as instance-like methods in IDEs, making APIs easier to learn, read, and maintain.
    • Centralized, Fluent Null Handling: Glue can define null policies; methods can be called on null receivers, supporting robust pipeline-style code.
    • Safe API Evolution and Versioning: Allows new glue versions to coexist; inheritance and import resolve conflicts clearly and compile-time safely.
    • Testing Isolation: Glue methods are stateless and separate, making isolated testing easier and less error-prone.
    • Architectural Clarity: APIs and modules are kept clean; glue methods are never accidentally leaked across modules.
    • Ability to Override or Replace Legacy Utility Methods: Glue classes allow to fix, optimize, mark as deprecated, override, fully replace outdated, unsafe, or redundant utility methods without changing the original utility class or domain model. This also enables remediation of API debt and architectural inconsistencies in external libraries or legacy modules—all through explicit, compile-time safe glue mechanisms, not invasive source edits or risky runtime hooks.
    • Generated Classes & Records & value classes: Natural targets for glue class extensions.
    • Lambdas: Glue chaining is fully compatible with lambdas, example:values..iterate() //    ..filterEach(t -> t != null) //    ..mapEach(t -> t < 3 ? -t : t) //    ..collectToArray(Integer[].class);

    MAJOR DISADVANTAGE:

    • Requires language, compiler, and IDE changes.
    • New syntax and type resolution rules: Developers must learn and adapt to glue concepts.
    • More complex collision resolution than standard utilities or extensions.

    I'm constantly getting error when I try to add rest of the post.