ProgrammingPro #85: Blazor Routing in C#, Kotlin 2.1's when Expressions, GraalVM JIT for Java, and Python Speed Boosts with Cython
Welcome to this week’s edition of ProgrammingPro!
In today’s Expert Insight, we bring you an excerpt from the recently published book, C# 13 and .NET 9 – Modern Cross-Platform Development Fundamentals - Ninth Edition, which demonstrates defining routable page components, passing route parameters, and navigating routes in Blazor.
News Highlights: Kotlin 2.1.0 previews advanced when expressions; Rust 1.83 enhances Multiplatform and Gradle tools; AWS Q Developer adds AI-driven testing and modernization; and Oracle launches GraalVM JIT for its JDK only.
My top 5 picks from today’s learning resources:
Hans Wennborg: C++ switch statements under the hood in LLVM🔧
Understanding JavaScript Hoisting: The Magic Behind Variable and Function Declarations🎩
Reaching Your Automatic Testing Goals by Enhancing Your Test Architecture🤖
Faster Features, Happier Customers: Introducing The Platform That Transformed Our Grocery App🚀
But there’s more, so dive right in.
Stay Awesome!
Divya Anne Selvaraj
Editor-in-Chief
🗞️News and Analysis🔎
Kotlin previews guard conditions in when expressions: Kotlin 2.1.0 introduces guard conditions for more flexible
when
expressions, non-local breaks/continues, and multi-dollar string interpolation as preview features.Rust 1.83 expands const capabilities: The updates improve Kotlin Multiplatform library publishing, add Swift export, stabilize Gradle DSLs, and enhance K2 compiler checks.
AWS enhances Q Developer: Test and review code, upgrade to modern .NET, migrate mainframe applications: Features include AI-driven unit testing, code reviews, operational troubleshooting, and migration tools.
Microsoft fixed slow package restore in .NET 9.0, but with annoying early bugs: The SDK introduces a 15x faster package restore with NuGet 6.12, but bugs like downloading unused packages remain.
Java News Roundup: Last of the JEPs Targeted to JDK 24, Quarkus 3.17, Maven 4.0-RC1, Kotlin 2.1: Updates also include Hibernate Search 7.2.2, Eclipse Vert.x 5.0, and the latest JDKUpdater version.
Oracle Ships GraalVM Java JIT Compiler - but Only in Its Own JDK: The compiler offers better performance and maintainability than standard OpenJDK JIT compilers.
New report finds signs of slowing supply chain security momentum, plateaued DevOps maturity: According to Snyk's State of Open Source report, organizations report reduced adoption of new tools and training due to security fatigue.
JavaScript-based APIs have the lowest quality scores among all languages: The 2024 treblle Anatomy of an API report also notes explosive AI-driven API growth, rising complexity, and the critical need for better governance.
🎓Tutorials and Learning Resources💡
Python
🎓Tutorial | Cython tutorial: How to speed up Python: Provides step-by-step guidance on optimizing Python functions, integrating Cython with Python libraries, compiling code, and profiling for speed improvements.
💡Goodbye Make and Shell, Hello... Python?: Advocates using Python for build and project tooling over traditional Makefiles and shell scripts, emphasizing its benefits for maintainability, debuggability, and flexibility.
For more Python resources, go to PythonPro
C# and .NET
🎓Tutorial | How to use ref structs in C# 13: Covers the implementation, benefits, limitations, and extended capabilities of ref structs in C# 13 for high-performance, stack-only memory management.
🎓Tutorial | File Operations C# .NET: Part 01 — File and Directory Handling: Covers path manipulation, copying, moving, deleting, exception handling, and best practices, using .NET 8, C# 12, and Visual Studio 2022.
🎓Tutorial | Deep Dive into .NET Hosted Services: Delves into the BackgroundService class, its lifecycle methods (StartAsync, StopAsync), and integration with the Host class for managing long-running tasks.
C and C++
🎥Hans Wennborg: C++ switch statements under the hood in LLVM: Explains how LLVM uses clustering, jump tables, bit masking, and binary search trees for efficient code generation and addresses edge cases.
💡Legacy Safety: The Wrocław C++ Meeting: Discusses the challenges of improving C++ memory safety focusing on the tension between two approaches: Profiles, incremental safety rules for existing code, and Safe C++, a borrow-checking approach.
🎓Tutorial | Build Your Own In-Memory Data Store with C: A Step-by-Step Guide (Part 2): Provides guidance for creating the table, inserting, retrieving, deleting, and cleaning up data, basic test setup, and compiling with CMake.
Java
🗞️Oracle's Java price hikes push CIOs to brew new licensing strategies: Many are exploring open-source Java alternatives, which could cut costs by 50%, but the transition requires top-level involvement to assess risks.
🎓Tutorial | Spring Security Guide:Part 1: Provides an overview of how security works in Spring-based web applications, focusing on middleware for authentication (identifying users) and authorization (checking permissions).
🎓Tutorial | Linked List Complexity: Delves into the efficiency of linked list operation for insertions and deletions compared to array-based structures, and provides examples of using Java's
LinkedList
class and more.
JavaScript and TypeScript
🎓Tutorial | Understanding JavaScript Hoisting: The Magic Behind Variable and Function Declarations: Explains the differences between
var
,let
,const
, function declarations, and function expressions.🎓Tutorial | React file nesting design pattern: Introduces the design pattern using the VSCode extension File Nesting Explorer, enabling a hierarchical folder structure that mirrors the UI/UX tree of the application.
💼Case Study | A leap in the evolution of Airtable’s codebase: Scaling TypeScript to thousands of projects: Discusses how Airtable scaled its codebase from 50 to nearly 3000 projects, reducing typechecking time by 65%.
Go
🎓Tutorial | Building a distributed log using S3 (under 150 lines of Go): Demonstrates how to build a durable, distributed log, covering its design for appending, reading, checksums, crash recovery, and failover handling.
💡Dependency management fatigue, or why I forever ditched React for Go+HTMX+Templ: Focuses on how the Go+HTMX+Templ stack allows developers to focus on feature development and minimize maintenance.
Rust
💼Case Study | Optimization adventures: making a parallel Rust workload 10x faster with (or without) Rayon: Dicusses optimization by replacing Rayon with a custom thread pool and work-stealing implementation.
📖Open Access Book | Writing NES Emulator in Rust: Covers essential topics such as emulating the NES CPU, memory management, picture processing unit (PPU), audio processing unit (APU), and input handling.
Swift
🎓Tutorial | Native Swift on Android, Part 2: Your First Swift Android App: Demonstrating how to build a "Hello Swift" app that integrates native Swift functionality and Kotlin/Jetpack Compose via bridging.
🎓Tutorial | Enum explained in-depth with code examples in Swift: Covers definitions, raw values, associated values, CaseIterable protocol, Equatable conformance, advanced usage with if/guard case, and more.
PHP
🎓Tutorial | Exploring PHP Lazy Objects: A Practical Implementation: Introduces PHP Lazy Objects, a new feature in PHP 8.4 that optimizes object initialization using two strategies: Ghost Objects and Virtual Proxies.
🎓Tutorial | Graceful Error Handling with Laravel’s rescue Function: Delves into Laravel’s
rescue
function which offers a concise and readable way to handle exceptions without disrupting application flow.
SQL
🎓Tutorial | Writing Composable SQL using Knex and Pipelines: Explains how to write composable SQL queries using Knex, a Node.js query builder, and pipelines for a functional programming approach.
🗞️AWS announces Aurora DSQL, a new distributed SQL database that promises virtually unlimited scalability: This serverless distributed SQL database offers 99.999% availability, strong consistency, and PostgreSQL compatibility.
Ruby
🎓Tutorial | Speeding up Ruby by rewriting C… in Ruby: Explores the challenges and progress in optimizing Ruby's performance, especially through rewriting C-based methods in Ruby to leverage Yet Another Ruby JIT.
🎓Tutorial | Calculating the largest known prime in Ruby: Explains how Ruby 3.4 introduces support for calculating large numbers like the largest known prime, which previously returned infinity.
Kotlin
🎓Tutorial | Kotlin Flows Animated (Scan, Fold, Reduce): Delves into Kotlin Flows' state accumulation operators, explaining their use cases with examples.
🎓Tutorial | Deploy Kotlin Mutliplatform WasmJS to Github Pages: Demonstrates using a GitHub Actions workflow to automate building and deploying a Kotlin/wasmJs project from a structured directory.
🌟Best Practices and Advice🚀
How to Use Programming Rules and Guidelines: Discusses the proper use of programming rules and guidelines, emphasizing their impact on code consistency and readability.
Navigating Responsible AI in the FinTech Landscape: Discusses the EU AI Act, balancing transparency and efficiency, cross-functional collaboration, and risk management, highlighting FinTech’s potential to lead in ethical AI adoption.
Reaching Your Automatic Testing Goals by Enhancing Your Test Architecture: Discusses integrating technical tools and human collaboration, focusing on trends over individual failures, using ML for auto-triaging, and more.
Faster Features, Happier Customers: Introducing The Platform That Transformed Our Grocery App: Discusses how Picnic transformed its app by adopting React Native, enabling faster feature delivery through cross-platform development, modular architecture, and real-time rule evaluation.
🧠Expert Insight📚
Here’s an excerpt from “Chapter 14: Building Interactive Web Components Using Blazor" in the book, C# 13 and .NET 9 – Modern Cross-Platform Development Fundamentals - Ninth Edition by Mark J. Price, published in November 2024.
How to define a routable page component
To create a routable page component, add the @page
directive to the top of a component’s .razor
file, as shown in the following markup:
@page "/customers"
The preceding code is the equivalent of a mapped endpoint in Program.cs
, as shown in the following code:
app.MapGet("/customers", () => ...);
The Router
component scans the assembly specifically in its AppAssembly
parameter for Blazor components with the @page
directive, registering their URL paths as endpoints.
At runtime, a page component is merged with any specific layout that you have specified in the Routes.razor
file <RouteView>
component. By default, the Blazor Web App project template defines MainLayout.razor
as the layout for page components.
Pro Tip:
Good Practice: By convention, put routable page Blazor components in the Components\Pages
folder.
How to navigate routes and pass route parameters
Microsoft provides a dependency service named NavigationManager
that understands Blazor routing and the NavLink
component. The NavigateTo
method is used to go to the specified URL.
Blazor routes can include case-insensitive named parameters, and your code can most easily access the values passed by binding the parameter to a property in the code block, using the [Parameter]
attribute, as shown in the following markup:
@page "/customers/{country}"
<div>Country parameter as the value: @Country</div>
@code {
[Parameter]
public string Country { get; set; }
}
The recommended way to handle a parameter that should have a default value when it is missing is to suffix the parameter with ?
and use the null-coalescing operator in the OnParametersSet
method, as shown in the following markup:
@page "/customers/{country?}"
<div>Country parameter as the value: @Country</div>
@code {
[Parameter]
public string Country { get; set; }
protected override void OnParametersSet()
{
// If the automatically set property is null, then
// set its value to USA.
Country = Country ?? "USA";
}
}
C# 13 and .NET 9 – Modern Cross-Platform Development Fundamentals - Ninth Edition was published in Novemver 2024. Packt library subscribers can continue reading the entire book for free or you can buy the book here!
Get the eBook for $39.99 $27.98
🛠️Useful Tools⚒️
AISuite: An open-source Python library providing a unified API for seamless integration and switching between multiple LLMs with minimal code changes.
zio-kafka: A ZIO-native client offering a functional, streams-based API for seamless Kafka integration with ZIO and ZIO Streams.
prisma: A next-generation ORM offering a type-safe query builder for Node.js and TypeScript, a declarative migration system, and a GUI data editor.
That’s all for today.
We have an entire range of newsletters with focused content for tech pros. Subscribe to the ones you find the most useful here.
If your company is interested in reaching an audience of developers, software engineers, and tech decision makers, you may want to advertise with us.
If you have any suggestions or feedback, or would like us to find you a learning resource on a particular subject, leave a comment below!