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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 22, 2025

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

      May 22, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 22, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 22, 2025

      Sam Altman says ChatGPT’s viral Ghibli effect “forced OpenAI to do a lot of unnatural things”

      May 22, 2025

      How to get started with Microsoft Copilot on Windows 11

      May 22, 2025

      Microsoft blocks employees from sending emails that mention “Palestine” or “Gaza”

      May 22, 2025

      I missed out on the Clair Obscur: Expedition 33 Collector’s Edition but thankfully, the developers are launching something special

      May 22, 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

      Perficient is Shaping the Future of Salesforce Innovation

      May 22, 2025
      Recent

      Perficient is Shaping the Future of Salesforce Innovation

      May 22, 2025

      Opal – Optimizely’s AI-Powered Marketing Assistant

      May 22, 2025

      Content Compliance Without the Chaos: How Optimizely CMP Empowers Financial Services Marketers

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

      Sam Altman says ChatGPT’s viral Ghibli effect “forced OpenAI to do a lot of unnatural things”

      May 22, 2025
      Recent

      Sam Altman says ChatGPT’s viral Ghibli effect “forced OpenAI to do a lot of unnatural things”

      May 22, 2025

      How to get started with Microsoft Copilot on Windows 11

      May 22, 2025

      Microsoft blocks employees from sending emails that mention “Palestine” or “Gaza”

      May 22, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: A Trying Block

    CodeSOD: A Trying Block

    May 22, 2025

    Mark sends us a very simple Java function which has the job of parsing an integer from a string. Now, you might say, “But Java has a built in for that, Integer.parseInt,” and have I got good news for you: they actually used it. It’s just everything else they did wrong.

    private int makeInteger(String s)
    {
      int i=0;
      try
      {
        Integer.parseInt(s);
      }
      catch (NumberFormatException e)
      {
        i=0;
        return i;
      }
      i=Integer.parseInt(s);
      return i;
    }
    

    This function is really the story of variable i, the most useless variable ever. It’s doing its best, but there’s just nothing for it to do here.

    We start by setting i to zero. Then we attempt to parse the integer, and do nothing with the result. If it fails, we set i to zero again, just for fun, and then return i. Why not just return 0? Because then what would poor i get to do?

    Assuming we didn’t throw an exception, we parse the input again, storing its result in i, and then return i. Again, we treat i like a child who wants to help paint the living room: we give it a dry brush and a section of wall we’re not planning to paint and let it go to town. Nothing it does matters, but it feels like a participant.

    Now, Mark went ahead and refactored this function basically right away, into a more terse and clear version:

    private int makeInteger(String s)
    {
      try
      {
        return Integer.parseInt(s);
      }
      catch (NumberFormatException e)
      {
        return 0;
      }
    }
    

    He went about his development work, and then a few days later came across makeInteger reverted back to its original version. For a moment, he wanted to be mad at someone for reverting his change, but no- this was in an entirely different class. With that information, Mark went and did a search for makeInteger in the code, only to find 39 copies of this function, with minor variations.

    There are an unknown number of copies of the function where the name is slightly different than makeInteger, but a search for Integer.parseInt implies that there may be many more.

    [Advertisement]
    Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHand TeX is a handwritten LaTeX symbol classifier
    Next Article Egghead is a simple trivia app

    Related Posts

    News & Updates

    Sam Altman says ChatGPT’s viral Ghibli effect “forced OpenAI to do a lot of unnatural things”

    May 22, 2025
    News & Updates

    How to get started with Microsoft Copilot on Windows 11

    May 22, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Microsoft says “ChatGPT isn’t better than Copilot,” but OpenAI’s companion reportedly received more visits in a day than Copilot did in a month

    Microsoft says “ChatGPT isn’t better than Copilot,” but OpenAI’s companion reportedly received more visits in a day than Copilot did in a month

    News & Updates

    10 GPTs for Software Developers

    Development

    This affordable Lenovo gaming PC is the one I recommend to most people. Here’s why

    Development

    Fast Flux is the New Cyber Weapon—And It’s Hard to Stop, Warns CISA

    Development

    Highlights

    CVE-2025-22476 – Dell Storage Center Dell Storage Manager Command Injection

    May 6, 2025

    CVE ID : CVE-2025-22476

    Published : May 6, 2025, 5:15 p.m. | 2 hours, 19 minutes ago

    Description : Dell Storage Center – Dell Storage Manager, version(s) 20.1.20, contain(s) an Improper Neutralization of Special Elements used in a Command (‘Command Injection’) vulnerability. A low privileged attacker with adjacent network access could potentially exploit this vulnerability, leading to Remote execution.

    Severity: 5.5 | MEDIUM

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    I switched to a $129 Android phone for a week, and it was surprisingly capable

    February 4, 2025
    Windows 10 is getting downgraded again — here’s what Microsoft is taking away this time

    Windows 10 is getting downgraded again — here’s what Microsoft is taking away this time

    April 10, 2025

    How to Use a PHP Text-to-Speech Library to Generate Audio with Realistic Voices with the ElevenLabs Artificial Intelligence API

    January 29, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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