Published Mar 16, 2015

Delegate all the things!

    Dive into the world of .NET delegates and event handlers, where the hosts of Coding Blocks unravel their impact on flexibility in runtime and code extensibility. They also explore the parallels in JavaScript and Java, shedding light on closure mechanics and event-driven architectures pivotal to modern, scalable programming.
    Episode Highlights
    Coding Blocks logo

    Popular Clips

    Episode Highlights

    • JavaScript Delegates

      JavaScript's approach to delegates is notably straightforward, leveraging anonymous functions and passing functions as parameters. Alan Underwood highlights how JavaScript treats functions like any other data type, allowing them to be passed around easily without the need for explicit delegate constructs 1. This flexibility became prominent during the jQuery revolution, where anonymous functions were heavily utilized, making higher-order functions a staple in JavaScript programming 2.

      JavaScript just treats everything the same. It doesn't matter whether it's a string, a number, a method, it doesn't care.

      --- Alan Underwood

      Joe Zack notes that while this ease of use is beneficial, it can lead to overuse, resulting in what is colloquially known as "callback hell" 2.

         

      Java Interfaces

      Java, lacking direct delegate support, creatively uses interfaces to achieve similar outcomes. Michael Outlaw explains that Java developers often employ interfaces with single method implementations to mimic delegate functionality 3. This approach requires developers to be more aware of the underlying types, contrasting with C#'s abstraction of delegates 3.

      Java, because they don't have delegates specifically, they get around it through creative uses of interfaces.

      --- Michael Outlaw

      Joe Zack adds that while this method is effective, it exposes developers to more of the implementation details compared to the more seamless experience in C# 4.

    Related Episodes