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

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

      June 4, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 4, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 4, 2025

      Smashing Animations Part 4: Optimising SVGs

      June 4, 2025

      I test AI tools for a living. Here are 3 image generators I actually use and how

      June 4, 2025

      The world’s smallest 65W USB-C charger is my latest travel essential

      June 4, 2025

      This Spotlight alternative for Mac is my secret weapon for AI-powered search

      June 4, 2025

      Tech prophet Mary Meeker just dropped a massive report on AI trends – here’s your TL;DR

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

      Beyond AEM: How Adobe Sensei Powers the Full Enterprise Experience

      June 4, 2025
      Recent

      Beyond AEM: How Adobe Sensei Powers the Full Enterprise Experience

      June 4, 2025

      Simplify Negative Relation Queries with Laravel’s whereDoesntHaveRelation Methods

      June 4, 2025

      Cast Model Properties to a Uri Instance in 12.17

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

      My Favorite Obsidian Plugins and Their Hidden Settings

      June 4, 2025
      Recent

      My Favorite Obsidian Plugins and Their Hidden Settings

      June 4, 2025

      Rilasciata /e/OS 3.0: Nuova Vita per Android Senza Google, Più Privacy e Controllo per l’Utente

      June 4, 2025

      Rilasciata Oracle Linux 9.6: Scopri le Novità e i Miglioramenti nella Sicurezza e nelle Prestazioni

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

    I test AI tools for a living. Here are 3 image generators I actually use and how

    June 4, 2025
    News & Updates

    The world’s smallest 65W USB-C charger is my latest travel essential

    June 4, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Google DeepMind Researchers Propose Matryoshka Quantization: A Technique to Enhance Deep Learning Efficiency by Optimizing Multi-Precision Models without Sacrificing Accuracy

    Machine Learning

    6 Mistakes Organizations Make When Deploying Advanced Authentication

    Development

    The Best Open-Source Tools & Frameworks for Building WordPress Themes

    Learning Resources

    Windows 10 removes Start menu jump lists (file list) for tiles in April 2025 Update

    Operating Systems

    Highlights

    Development

    APT29 Hackers Target High-Value Victims Using Rogue RDP Servers and PyRDP

    December 20, 2024

    The Russia-linked APT29 threat actor has been observed repurposing a legitimate red teaming attack methodology…

    Nite Riot: Minimalism Gets a Wild Side

    April 15, 2025

    Permanent Record Deletion with Laravel’s forceDestroy

    January 20, 2025

    Web Development Tools to Help You Create a Better Website

    February 25, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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