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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 2, 2025

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

      June 2, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 2, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 2, 2025

      How Red Hat just quietly, radically transformed enterprise server Linux

      June 2, 2025

      OpenAI wants ChatGPT to be your ‘super assistant’ – what that means

      June 2, 2025

      The best Linux VPNs of 2025: Expert tested and reviewed

      June 2, 2025

      One of my favorite gaming PCs is 60% off right now

      June 2, 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

      `document.currentScript` is more useful than I thought.

      June 2, 2025
      Recent

      `document.currentScript` is more useful than I thought.

      June 2, 2025

      Adobe Sensei and GenAI in Practice for Enterprise CMS

      June 2, 2025

      Over The Air Updates for React Native Apps

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

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025
      Recent

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025

      Microsoft says Copilot can use location to change Outlook’s UI on Android

      June 2, 2025

      TempoMail — Command Line Temporary Email in Linux

      June 2, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Every Day

    CodeSOD: Every Day

    February 20, 2025

    There are real advantages to taking a functional programming approach to expressing problems. Well, some problems, anyway.

    Kevin sends us this example of elegant, beautiful functional code in C#:

    //create a range of dates
    List<DateTime> dates = Enumerable.Range
      (0, 1 + settings.EndDate.Subtract   
      (settings.BeginDate).Days).Select
      (offset => settings.BeginDate.AddDays(offset)).ToList();
    foreach (DateTime procDate in dates)
    {
    /*.snip.*/
    }
    

    If you’re not sure what this code does, it’s okay- Kevin rewrote it and “ruined” it:

    DateTime procDate = settings.BeginDate;
    while(procDate <= settings.EndDate)
    {
    /*.snip.*/
    procDate= procDate.AddDays(1);
    }
    

    The goal of this code is simply to do something for every day within a range of dates. These two approaches vary a bit in terms of readability though.

    I guess the loop in the functional version isn’t mutating anything, I suppose. But honestly, I’m surprised that this didn’t take the extra step of using the .ForEach function (which takes a lambda and applies it to each parameter). Heck, with that approach, they could have done this whole thing in a single statement.

    [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 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleFOSS Weekly #25.08: Ubuntu 25.04 Features, Conky Setup, Plank Reloaded and More Linux Stuff
    Next Article Developer Spotlight: Fabio Carretti

    Related Posts

    News & Updates

    How Red Hat just quietly, radically transformed enterprise server Linux

    June 2, 2025
    News & Updates

    OpenAI wants ChatGPT to be your ‘super assistant’ – what that means

    June 2, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Anker’s first wall charger with a display and new TSA-certified power bank roll out at CES 2025

    News & Updates

    Finding a forever home for FigPals

    Web Development

    MMRole: A New Artificial Intelligence AI Framework for Developing and Evaluating Multimodal Role-Playing Agents

    Development

    Custom Software Development : A Detailed Guide (2025)

    Development

    Highlights

    Development

    New Chrome Zero-Day Vulnerability CVE-2024-4761 Under Active Exploitation

    May 14, 2024

    Google on Monday shipped emergency fixes to address a new zero-day flaw in the Chrome…

    Pinta 3.0 Released With New Effects and GTK4 Port

    April 12, 2025

    Here’s how to register for 2XKO’s Alpha Lab playtests on Xbox Series X|S and Windows PC

    June 26, 2024

    CVE-2025-4060 – PHPGurukul Notice Board System SQL Injection Vulnerability

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

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