Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    HONOR Magic V5 now available with telco partners from as low as RM70/month

    Trump closes the online shopping loophole that beat tariffs

    Tapo DL100 review: A Wi-Fi smart lock for a whole lot less

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      AI models may be accidentally (and secretly) learning each other’s bad behaviors

      July 30, 2025

      Another Chinese AI model is turning heads

      July 15, 2025

      AI chatbot Grok issues apology for antisemitic posts

      July 13, 2025

      Apple sued by shareholders for allegedly overstating AI progress

      June 22, 2025

      How far will AI go to defend its own survival?

      June 2, 2025
    • Business

      Cloudflare open-sources Orange Meets with End-to-End encryption

      June 29, 2025

      Google links massive cloud outage to API management issue

      June 13, 2025

      The EU challenges Google and Cloudflare with its very own DNS resolver that can filter dangerous traffic

      June 11, 2025

      These two Ivanti bugs are allowing hackers to target cloud instances

      May 21, 2025

      How cloud and AI transform and improve customer experiences

      May 10, 2025
    • Crypto

      Shiba Inu Price’s 16% Drop Wipes Half Of July Gains; Is August In Trouble?

      July 30, 2025

      White House Crypto Report Suggests Major Changes to US Crypto Tax

      July 30, 2025

      XRP Whale Outflows Reflect Price Concern | Weekly Whale Watch

      July 30, 2025

      Stellar (XLM) Bull Flag Breakout Shows Cracks as Momentum Fades

      July 30, 2025

      Binance Listing Could Be a ‘Kiss of Death’ for Pi Network and New Tokens

      July 30, 2025
    • Technology

      Trump closes the online shopping loophole that beat tariffs

      July 31, 2025

      Tapo DL100 review: A Wi-Fi smart lock for a whole lot less

      July 31, 2025

      This Alienware 4K OLED gaming monitor is over $400 off right now

      July 31, 2025

      Asus ROG Xbox Ally releases August with high price, according to leaks

      July 31, 2025

      This high-capacity solar power bank is down to its lowest price

      July 31, 2025
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Check BMI
    Tech AI Verse
    You are at:Home»Technology»Locality of Behaviour (2020)
    Technology

    Locality of Behaviour (2020)

    TechAiVerseBy TechAiVerseJuly 3, 2025No Comments4 Mins Read0 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    BMI Calculator – Check your Body Mass Index for free!

    Locality of Behaviour (2020)

    Carson Gross

    May 29, 2020

    “The primary feature for easy maintenance is locality: Locality is that characteristic of source code that enables a
    programmer to understand that source by looking at only a small portion of it.” – Richard Gabriel

    The LoB Principle

    Locality of Behaviour is the principle that:

    The behaviour of a unit of code should be as obvious as possible by looking only at that unit of code

    Discussion

    The LoB principle is a simple prescriptive formulation of the quoted statement from Richard Gabriel.
    In as much as it is possible, and in balance with other concerns, developers should strive to make the behaviour of
    a code element obvious on inspection.

    Consider two different implementations of an AJAX request in HTML, the first in htmx:

    <button hx-get="/clicked">Click Mebutton>
    

    and the second in jQuery:

      $("#d1").on("click", function(){
        $.ajax({
             /* AJAX options... */
        });
      });
    
    <button id="d1">Click Mebutton>
    

    In the former, the behaviour of the button element is obvious on inspection, satisfying the LoB principle.

    In the latter, the behaviour of the button element is spread out amongst multiple files. It is difficult to know
    exactly what the button does without a total knowledge of the code base. This “spooky action at a distance” is a source
    of maintenance issues and stands in the way of developers understanding of the code base.

    The htmx example demonstrates good Locality of Behaviour, while the jQuery example has poor Locality of Behaviour.

    Surfacing Behaviour vs. Inlining Implementation

    A common objection to Locality of Behaviour is that it is inlining implementation details within a code unit, making the
    code unit less abstract and more brittle. However, it is important to make the distinction between inlining the
    implementation of some behaviour and inlining the invocation (or declaration) of some behaviour.

    Consider functions in most programming languages: there is a distinction between the declaration of function and its
    use at call sites. A good function abstracts away its implementation details, but is also invoked in an obvious manner,
    without any spooky action at a distance.

    Increasing the obviousness of the behaviour of an element is, ceteris paribus, a good thing, but it falls to both end-developers
    and especially framework developers to make LoB both as easy and as conceptually clean as possible.

    Conflict With Other Development Principles

    The LoB will often conflict with other software development principles. Two important ones
    are:

    • DRY – Don’t Repeat Yourself

      Software developers typically strive to avoid redundancy in their code or data. This has come to be called “Staying DRY”,
      i.e. Don’t Repeat Yourself. Like other software design principles this, on its own, is a good thing. htmx, for example,
      allows you to place many attributes on parent elements in a DOM and avoid repeating these attributes on children. This is a
      violation of LoB, in favor of DRY, and such tradeoffs need to be made judiciously by developers.

      Note that the further behaviour gets from the code unit it effects, the more severe the violation of LoB. If it is
      within a few lines of the code unit, this is less serious than if it is a page away, which is less serious than if
      it is in a separate file entirely.

      There is no hard and fast rule, but rather subjective tradeoffs that must be made as software developers.

    • SoC – Separation Of Concerns

      Separation of concerns a design principle for separating a computer program into distinct sections such that each
      section addresses a separate concern. A canonical example of this is splitting HTML, CSS, and Javascript. Again, on its own and
      in isolation this may, indeed, be a good thing. Inlining styles has become more prevalent lately,
      but there are still strong arguments in favor of SoC in this regard.

      Note that SoC is, however, in conflict with LoB. By tweaking a CSS file the look and, to an extent, behaviour of an
      element can change dramatically, and it is not obvious where this dramatic change came from. Tools can help to an extent
      here, but there is still “spooky action at a distance” going on.

      Again, this isn’t to condemn SoC wholesale, just to say that there are subjective tradeoffs that must be made when
      considering how to structure your code. The fact that inline styles have become more prevalent as of late is an
      indication that SoC is losing some support amongst developers.

    Conclusion

    LoB is a subjective software design principle that can help make a code base more humane and maintainable. It must be traded
    off against other design principles and be considered in terms of the limitations of the system a code unit is
    written in, but, as much as is it is practical, adherence to this principle will increase your software maintainability,
    quality and sustainability.

    BMI Calculator – Check your Body Mass Index for free!

    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticlePeasant Railgun
    Next Article Introducing tmux-rs
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    Trump closes the online shopping loophole that beat tariffs

    July 31, 2025

    Tapo DL100 review: A Wi-Fi smart lock for a whole lot less

    July 31, 2025

    This Alienware 4K OLED gaming monitor is over $400 off right now

    July 31, 2025
    Leave A Reply Cancel Reply

    Top Posts

    Ping, You’ve Got Whale: AI detection system alerts ships of whales in their path

    April 22, 202533 Views

    6.7 Cummins Lifter Failure: What Years Are Affected (And Possible Fixes)

    April 14, 202532 Views

    New Akira ransomware decryptor cracks encryptions keys using GPUs

    March 16, 202529 Views

    OpenAI details ChatGPT-o3, o4-mini, o4-mini-high usage limits

    April 19, 202522 Views
    Don't Miss
    Gadgets July 31, 2025

    HONOR Magic V5 now available with telco partners from as low as RM70/month

    HONOR Magic V5 now available with telco partners from as low as RM70/month Following strong…

    Trump closes the online shopping loophole that beat tariffs

    Tapo DL100 review: A Wi-Fi smart lock for a whole lot less

    This Alienware 4K OLED gaming monitor is over $400 off right now

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    HONOR Magic V5 now available with telco partners from as low as RM70/month

    July 31, 20252 Views

    Trump closes the online shopping loophole that beat tariffs

    July 31, 20252 Views

    Tapo DL100 review: A Wi-Fi smart lock for a whole lot less

    July 31, 20252 Views
    Most Popular

    Xiaomi 15 Ultra Officially Launched in China, Malaysia launch to follow after global event

    March 12, 20250 Views

    Apple thinks people won’t use MagSafe on iPhone 16e

    March 12, 20250 Views

    French Apex Legends voice cast refuses contracts over “unacceptable” AI clause

    March 12, 20250 Views
    © 2025 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.