ProgrammingPro #41: Python Gen AI Processor, C++ flat_map, Master System Design, and TCP servers in Rust
Bite-sized actionable content, practical tutorials, and resources for programmers
Welcome to a brand new issue of ProgrammingPro!
In today’s Expert Insight we bring you an exclusive excerpt from the book The MVVM Pattern in .NET MAUI by Pieter Nijs, that gives you some tips to deal with frequent custom control and converter problems.
News Highlights: The Rust-based Zed editor is now open source, offering a fast, OpenAI and GitHub Copilot integrated alternative for developers, while TypeScript 5.4 introduces improved type management. Meanwhile, Deno 1.4's support for the Temporal API promises a more reliable approach to JavaScript date handling.
My top 5 picks from today’s learning resources:
Mastering System Design - A Comprehensive Guide to System Scaling for Millions📈
Infrastructure as Code - Best Practices, Benefits & Examples🏗️
But there’s more, so dive right in.
Stay Awesome!
Divya Anne Selvaraj
Editor-in-Chief
PS: If you have any food for thought, feedback, or would like us to find you a specific Programming learning resource for our next issue, take the survey! As a thank you, we will send you one free Packt credit to buy a book of your choice.
🗞️News and Analysis🔎
Fixing bug-prone JavaScript dates: Deno 1.4 adds its support for Temporal API: The API, still under development, offers improved functionality like unambiguous timezone handling and immutable date objects, enhancing reliability and developer experience. Read to discover a more robust and developer-friendly approach to date/time manipulation.
Rust-based Zed editor now open source – with built-in support for OpenAI and GitHub Copilot: Built in Rust, the editor contrasts with VS Code in its fast performance and streamlined interface, despite limited plugin and language support, and is currently available only for Mac. Read to discover an alternative to traditional editors like VS Code, especially for Rust, TypeScript, and Python development.
Computer scientists invent simple method to speed cache sifting: Emory and Carnegie Mellon University computer scientists have developed SIEVE, a new open-source algorithm for web cache management. Read to learn how SIEVE's innovative approach enables optimizing web application performance and handling large-scale internet traffic.
A Year of C++ Improvements in Visual Studio: These improvements include cross-platform development support, productivity tools like Sticky Scroll and Brace Pair Colorization, and game development features for Unreal Engine. Read to learn about the latest updates and features in Visual Studio for C++ development.
TypeScript 5.4 beta arrives: This Microsoft update to the strongly typed JavaScript variant, includes improved type narrowing in function closures and a NoInfer utility type to manage type inferences. Read to learn more.
🎓Tutorials and Learning Resources💡
Python
🎓Tutorial | Building a Generative AI Processor in Python: This tutorial details the integration of a Gen AI Model with Apache NiFi 2.0.0 using the IBM WatsonX Python SDK. Read for a guide that will take you through selecting a model, testing in WatsonX's Prompt Lab, and developing a Python processor.
🎥🎓Tutorial | Getting Started With CUDA for Python Programmers: This video tutorial simplifies the complexities of CUDA programming and demonstrates its accessibility when combined with PyTorch. Watch to learn how to harness the power of GPUs for enhanced performance in your projects.
Python types have an expectations problem: This article highlights that while type annotations in Python are valuable for static analysis by tools like MyPy, they do not enforce type checking at runtime, which can lead to an "expectations problem" for developers. Read to learn about the the need for external type checking tools.
Java
🎓Tutorial | Machine learning algorithms for Java developers: This article emphasizes the importance of ML and provides Java-based examples, demonstrating how to set up, develop, and train prediction functions. Read to learn how to work with ML algorithms in Java.
Mastering Exception Handling in Java CompletableFuture - Insights and Examples: This article talks about the Java tool that provides methods like exceptionally() and handle() to effectively manage and handle unexpected errors in asynchronous tasks. Read to learn effective exception handling techniques.
Code Coverage Tools in Java Spring Boot - A Comprehensive Guide: This article, provides a practical setup guide for tools like Unlogged, JaCoCo, Cobertura, and Clover. Read to learn how to effectively integrate these tools to generate reports.
Go
Go memory metrics demystified: This guide breaks down memory usage into process and kernel memory, focusing on Go runtime-managed memory. Read to learn techniques for analyzing and managing memory in Go applications.
Augmenting Developmental Efficiency through Goland and MongoDB Concordance: Golang, known for its speed and simplicity, and MongoDB, recognized for its flexibility, together offer a potent combination for developing scalable and high-performance applications. Read to learn about integration best practices.
PHP
How I made it impossible to write spaghetti code: This article details the development of a static analyzer for PHP that utilizes cyclomatic complexity, a metric for code complexity based on the control flow graph's nodes and edges. Read to learn how to implement this metric.
Mastering Laravel Routes - A Comprehensive Guide for All Skill Levels: This guide covers how to define routes, pass parameters, utilize middleware for authentication, organize routes, and much more. Read to learn how to effectively manage web and API routes.
SQL
Creating a Next.js Dashboard for SQL Data Visualization: This guide covers how to combine Next.js with Flexmonster and Recharts to create efficient, scalable data visualization web applications. Read to learn how to integrate SQL data seamlessly with modern web technologies.
SQL Murder Mystery: This interactive game is designed to sharpen SQL skills through solving a fictional crime in SQL City, blending learning with entertainment for both beginners and experienced users. Give it a try to learn advanced concepts and database structure exploration techniques.
Scala/Apache Spark
🎓Tutorial | Load and transform data with Apache Spark Scala DataFrames: In this tutorial, you'll learn about DataFrames as two-dimensional labeled data structures, Spark's Dataset API, and practical tasks like loading data, combining DataFrames, filtering, selecting columns, and saving DataFrames. Read for insights into efficient data handling.
Kotlin
🎓Tutorial | How to Migrate an Android Project to Kotlin Multiplatform (KMP): This video tutorial teaches you how to enable shared code between Android and iOS platforms. Watch for step-by-step instructions for converting an Android application to a Kotlin Multiplatform project.
Understanding Kotlin sealed class: This article will teach you how to effectively use Kotlin sealed classes to create more predictable and type-safe applications. Read to understand the importance of restricted class hierarchies and their impact on compile-time type checking.
C/C++/C#
Exploring C++23’s flat_map: std::flat_map functions as a wrapper around std::vector, ensuring sorted elements, and supports operations like insert, erase, and emplace. Read to gain insights into utilizing the container for optimized performance.
Avoid These C# Testing Patterns... Unless They Actually Work!: The presenter of this video, while acknowledging the value of black-box testing where only the external behavior is verified, argues for the value of also testing implementation details in certain scenarios. Watch for insights into various approaches.
The C Bounded Model Checker (CBMC) - Criminally Underused: This article details CBMC’s installation, usage examples, and its ability to handle various types of assertions and potential errors in code. Read to learn about CBMC's utility in verifying C code and how to use it.
JavaScript and TypeScript
💼Case Study | TypeScript Might Not Be Your God - Case Study of Migration From TS to JSDoc: This article discusses the synergy between JSDoc and TypeScript for enhancing JavaScript typing, particularly for projects considering migration from pure JavaScript to TypeScript. Read if you are on the fence about fully migrating your project to TypeScript.
JavaScript stack for real-time reactive LLM heavy workloads: This all-JavaScript stack features Qwik, BullMQ, Redis, PostgreSQL, and the OpenAI API. Read for insights into
architecture efficiency, real-time responsiveness, and overcoming LM API limitations.
3 Simple Ways to Merge Objects in TypeScript: Methods covered include pread syntax, Lodash's merge function, and Object.assign. Read to understand each method's depth of copy and impact on object references, aiding in efficient and bug-free coding.
.NET
🎓Tutorial | Demystifying the Code First approach in EF Core: Code First allows for constructing a data model without a pre-existing database, offering flexibility and control over database schema and object mapping. Read to learn how to implement the Code First approach in EF Core
Improving ASP.NET Core Security By Putting Your Cookies On A Diet: This blog post addresses two key security issues in ASP.NET Core authentication: large cookie sizes and vulnerabilities during signout. Read to learn how to minimize cookie size and prevent cookie misuse post-signout.
Ruby
Ruby on Rails load testing habits: This article, emphasizes testing on servers, not development machines, to prepare for traffic surges. Read to learn how to optimize performance and prepare for high-traffic events.
Machine Learning - An Introduction to CART Decision Trees in Ruby: This article focuses on CART trees, which use the Gini Index to measure impurity and choose splits to minimize this impurity. Read to gain practical insights for binary classification tasks.
Rust
Process spawning performance in Rust: This article delves into the intricate details of process spawning in Rust and its performance implications in a distributed computing environment, especially on Linux systems. Read if you work with large-scale, high-performance computing applications.
🎓Tutorial | TCP Servers in Rust: This article covers essential methods like TcpListener::bind and TcpStream::connect, and demonstrates handling incoming connections and reading/writing data streams. Read to learn how to build robust TCP servers in Rust, including managing connections and data transfer.
Swift
ScrollView Bounce Behavior configuration in SwiftUI: This article teaches you how to customize the bounce behavior of ScrollView in SwiftUI. Read to learn how to enhance user interfaces by adapting scroll behaviors based on content size and scroll direction.
A new access modifier in Swift: package: Swift 5.9 has introduced "package," a new access modifier, enabling developers to restrict code access within a package, facilitating modular code sharing without exposing details externally. Read to learn more about package’s benefits.
Microservices
IntelliJ and Java Spring Microservices - Productivity Tips With GitHub Copilot: This review details the author's experience with Copilot, emphasizing its utility in exception handling, unit testing, logging, and code commenting. Read to gain insights into practical applications of GitHub Copilot in Java Spring Microservices development.
Game Dev.
Getting Started with Game Development: This article introduces game development as a blend of coding creativity and technical skill, highlighting the significance of programming in creating engaging video games. Read to learn about practical steps you need to take to start creating your own games.
🌟Best Practices🚀
Source Code Management (SCM) and Branching Strategies for CI/CD: This article covers the workings of SCM, its significance in DevOps, various SCM strategies for CI/CD, best practices, and tools, emphasizing the need for seamless integration and delivery in modern software development. Read to enhance your ability to streamline development workflows.
Mastering System Design - A Comprehensive Guide to System Scaling for Millions: This tutorial focuses on vertical and horizontal scaling, load balancing, and data replication, using a fictitious local delivery startup as a case study. Read to learn practical strategies for scaling software systems for global solutions.
How Much Architecture Is “Enough?” - Balancing the MVP and MVA Helps You Make Better Decisions: This article delves into avoiding over-investment in MVA while addressing current challenges of MVP, understanding MVP success is essential for MVA relevance, and considering MVA alongside MVP's evolution. Read to learn how to ensure long-term viability and adaptability of software products.
How to Optimize Your CSS Code for Faster Web Pages: This article covers techniques such as writing concise CSS, using shallow selectors, segmenting code, and optimizing CSS delivery. Read to learn practical methods to refine CSS for better performance.
Infrastructure as Code - Best Practices, Benefits & Examples: This article covers the efficiency of IaC in provisioning, scaling, managing infrastructure, the benefits of version control integration, and declarative vs. imperative approaches. Read for examples using tools like Terraform, Pulumi, and Bicep.
Take the Survey, Get a Packt Credit
🧠 Expert Insight 📚
Here’s an exclusive excerpt from “Chapter 14, Troubleshooting and Debugging Tips” in the book, The MVVM Pattern in .NET MAUI by Pieter Nijs. The book is a comprehensive guide on using the MVVM design pattern in .NET MAUI projects, focusing on writing robust, maintainable, and testable code.
Frequent custom control and converter problems
Most of the issues that arise when working with custom controls regularly have to do with bindable properties. Often, a small
typo or a little oversight might cause your custom control to not react as expected or to display the wrong data.
Troubleshooting bindable properties
On a custom control, there is a lot of ceremony needed to define bindable properties. It’s very easy to make a mistake that is very hard to spot when troubleshooting. Here are a couple of things to look out for:
The propertyName parameter in the Create method: Make sure the propertyName parameter matches the exact naming of the property:
public static readonly BindableProperty
IsFavoriteProperty =
BindableProperty.Create(nameof(IsFavorite), …);
public bool IsFavorite
{
...
}
As this code sample shows, it is advised to use the nameof expression to prevent typos!
The returnType parameter in the Create method: The second parameter of the BindableProperty’s Create method is the returnType, which must match the type of the property:
public static readonly BindableProperty
IsFavoriteProperty =
BindableProperty.Create(nameof(IsFavorite),
typeof(bool), …);
public bool IsFavorite
{
...
}
The declaringType parameter in the Create method: This parameter should be the type of the class where the property is defined:
public partial class FavoriteControl : ContentView
{
public static readonly BindableProperty
IsFavoriteProperty =
BindableProperty.Create(...
typeof(FavoriteControl),...);
public bool IsFavorite
{
...
}
It’s also important to make sure the getter and setter of the property call the GetValue and SetValue, passing in the correct BindableProperty:
public static readonly BindableProperty IsFavoriteProperty = ...
public bool IsFavorite
{
get => (bool)GetValue(IsFavoriteProperty);
set => SetValue(IsFavoriteProperty, value);
}
Whenever there is a discrepancy between the provided values in the BindableProperty’s Create method and the values on the control itself, or when the property doesn’t get or set the value correctly on the BindableProperty, the bindable property will not work as expected. So, it’s crucial to double-check these values!
Binding to the BindingContext
As already stipulated in Chapter 11, Creating MVVM-Friendly Controls, it is crucial that custom controls don’t depend on their BindingContext! The reason is that you can’t control that, as it is inherited from the parent the custom control is used on. Instead, you should only bind to the (bindable) properties that you’ve defined on the control itself. This can easily be achieved by leveraging relative or element binding, just like we did with the FavoriteControl:
<Image
HeightRequest="{Binding HeightRequest,
Source={x:Reference icon}}"
IsVisible="{Binding IsInteractive,
Source={RelativeSource AncestorType={x:Type
local:FavoriteControl}}}"
... />
Any binding statements on a custom control that don’t have an explicit source set will bind to the BindingContext of the parent, which we don’t control. When a custom control works in one place but not in the other, chances are high that there is some binding going on that is not relative to the control itself. So, always double-check the binding statements in your custom control!
Finally, let’s have a quick look at the issues that might arise when working with value converters.
Value converter issues
Converters play a crucial role in data transformation within your app. However, their logic might not always behave as expected. It’s a seemingly trivial issue, but one that is frequently underestimated. The solution? Simple yet powerful: write unit tests! In Chapter 13, Unit Testing, we’ve highlighted how easy it is to unit test value converters. Paying attention to the logic within converters, testing them rigorously, and handling special cases will ensure that your converters perform reliably.
Packt subscribers can continue reading for free here. The MVVM Pattern in .NET MAUI by Pieter Nijs, was published in November 2023. You can buy the book here.
🛠️ Useful Tools ⚒️
Filippo.io/mlkem768: a Go implementation of the ML-KEM-768 post-quantum key exchange mechanism, optimized for security, readability, and spec validation.
foundations: an open-source Rust library by Cloudflare for developing distributed, production-grade systems, focusing on ease of use and operational efficiency.
DUCKDB-NSQL-7B: a text-to-SQL LLM specifically designed for DuckDB, aimed at enhancing SQL query formulation with AI assistance, making it easier for users to leverage DuckDB's full capabilities without extensive reference to documentation.
SpatiaLite: an open-source library that extends SQLite with spatial database capabilities, enabling the storage, manipulation, and query of geographic data within the SQLite database framework.
scala-native: an optimizing ahead-of-time compiler and lightweight managed runtime for Scala, offering low-level primitives, seamless interop with native code, and instant startup times.
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. Complete ProgrammingPro archives can be found here. Complete PythonPro archives are 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 feedback, leave a comment below.