Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 30, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 30, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 30, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 30, 2025

      Does Elden Ring Nightreign have crossplay or cross-platform play?

      May 30, 2025

      Cyberpunk 2077 sequel enters pre-production as Phantom Liberty crosses 10 million copies sold

      May 30, 2025

      EA has canceled yet another game, shuttered its developer, and started more layoffs

      May 30, 2025

      The Witcher 3: Wild Hunt reaches 60 million copies sold as work continues on The Witcher 4

      May 30, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      How Remix is shaking things up

      May 30, 2025
      Recent

      How Remix is shaking things up

      May 30, 2025

      Perficient at Kscope25: Let’s Meet in Texas!

      May 30, 2025

      Salesforce + Informatica: What It Means for Data Cloud and Our Customers

      May 30, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Does Elden Ring Nightreign have crossplay or cross-platform play?

      May 30, 2025
      Recent

      Does Elden Ring Nightreign have crossplay or cross-platform play?

      May 30, 2025

      Cyberpunk 2077 sequel enters pre-production as Phantom Liberty crosses 10 million copies sold

      May 30, 2025

      EA has canceled yet another game, shuttered its developer, and started more layoffs

      May 30, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Mr Number

    CodeSOD: Mr Number

    January 6, 2025

    Ted’s company hired a contract team to build an application. The budget eventually ran out without a finished application, so the code the contract team had produced was handed off to Ted’s team to finish.

    This is an example of the Ruby code Ted inherited:

    def self.is_uniqueness(mr_number)
        out = false
        mrn = PatientMrn.find_by_mr_number(mr_number)
        if mrn
          out = true
          return mrn
        end
        return nil
      end
    

    The function is called is_uniqueness which is definitely some language barrier naming (is_unique is a more English way of wording it). But if we trace through the logic, this is just a wrapper around PatientMrn.find_by_mr_number– it returns an “mrn”.

    So, the first obvious problem: this isn’t checking uniqueness in any way, shape or form.

    Then there’s the whole check for a valid record- either we find a record or we return nil. But since find_by_mr_number is clearly returning something falsy, that doesn’t seem necessary.

    And that is the default behavior for the Rails generated find_by methods- they just return nil if there are no records. So none of the checks are needed here. This whole method isn’t needed here.

    Finally, there’s out. I have no idea what they were trying to accomplish here, but it smells like they wanted a global variable that they could check after the call for error statuses. If that was their goal, they failed in a few ways- first, returning nil conveys the same information. Second, global variables in Ruby get a $ sigil in front of them.

    What the out variable truly represents is “do I want out of this codebase?” True. That is definitely true.

    [Advertisement]
    BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleMy favorite robot mower adds two more affordable ‘mini’ units for smaller yards
    Next Article Autostart AppImage Applications in Linux

    Related Posts

    News & Updates

    Does Elden Ring Nightreign have crossplay or cross-platform play?

    May 30, 2025
    News & Updates

    Cyberpunk 2077 sequel enters pre-production as Phantom Liberty crosses 10 million copies sold

    May 30, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    ALPINE: Autoregressive Learning for Planning in Networks

    Development

    How to Ditch Your Friends, Eat Tomatoes, and Influence People? The Full eBook Leaked

    Artificial Intelligence

    CVE-2025-5153 – CMS Made Simple Design Manager Module Cross-Site Scripting Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Golden Gemini: A new approach in Speech AI

    Artificial Intelligence

    Highlights

    Artificial Intelligence

    The Dark Coffee

    April 7, 2025

    My name is Srinidhi Ranganathan, and I’ve always been… well, a little jumpy. Not like,…

    My 5 favorite note-taking apps for staying organized on a desktop

    December 31, 2024

    New Withings feature connects you with a cardiologist when it senses you need one

    January 7, 2025
    Last Week in AI #306: Astrocade, Llama 4, Nova Act

    Last Week in AI #306: Astrocade, Llama 4, Nova Act

    April 8, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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