ProgrammingPro #63: SwiftUI Reactive Flow, CISA Memory-Safety Report, Positron Python IDE, and Spark Guide
Bite-sized actionable content, practical tutorials, and resources for programmers
Welcome to this week’s edition of ProgrammingPro!
In today’s Expert Insight, we bring you an excerpt from the recently published book,
Swift Cookbook - Third Edition, which demonstrates a simple reactive flow in SwiftUI using Combine.
News Highlights: New CISA report stresses the need for memory-safe languages; Positron, a new R and Python IDE, simplifies setup; OpenJDK proposes value classes for Java; and Angular 18 introduces zoneless change detection and improved server-side rendering.
My top 5 picks from today’s learning resources:
Building REST API Using Spring Boot - A Comprehensive Guide🌐
Create npm package with CommonJS and ESM support in TypeScript📦
Also, within this issue we are completing coverage of all your resource requests sent to us through the June survey. But there’s more, so dive right in.
Stay Awesome!
Divya Anne Selvaraj
Editor-in-Chief
PS: This month’s survey is now open! Do take the oppotunity to give us your feedback on ProgrammingPro, request specific learning resources, and get your one Packt Credit for the month.
PPS: We are working on a special AI for programming issue 🤖 that will be coming to you next week. Keep your eyes peeled!👀
🗞️News and Analysis🔎
New CISA report highlights need to transition to memory-safe languages: The report found that 52% of critical OpenSSF projects are written in memory-unsafe languages. Read for insights into the challenges in transitioning existing projects.
Rust types team moves forward on next-gen trait solver: The team aims to enable it across the standard library and compiler, resolving design questions and minor issues. Read for insights into the trait solver’s development.
Maker of RStudio launches new R and Python IDE: Positron simplifies setup for both languages, includes built-in data exploration tools, and supports extensions via OpenVSX. Read to learn about Positron's features and capabilities.
OpenJDK proposal would bring value classes and objects to Java: The proposal aims to simplify handling simple values and improve memory and efficiency. Read to learn about upcoming enhancements to Java's model.
Java in Education Initiative Aims to Empower the Next Generation of Developers: Launched by the JCP Executive Committee, the initiative promotes Java technology in educational institutions. Read to learn how you can get involved.
Angular 18 Introduces Zoneless Change Detection: A new developer hub, stable Material 3 components, improved server-side rendering, and enhanced forms have also been introduced. Read to learn about all the updates.
GitHub improves supply chain security with general availability of Artifact Attestations: The release allows users to verify GitHub Actions artifacts before deployment. Read to learn how to integrate Artifact Attestations into your workflow.
🎓Tutorials and Learning Resources💡
Python
🎓Tutorial | Apache Spark - A Comprehensive Technical Guide: Provides a detailed overview of Apache Spark, with a focus on using PySpark for data processing and analytics. Read to learn how to set up and configure Spark.
🎓Tutorial | Understanding the Python Mock Object Library: Explains how Python’s unittest.mock library works to improve test reliability and efficiency. Read to learn how to create and manage mock objects.
For more Python resources go to PythonPro
C# and .NET
🎓Tutorial | Create a Razor Pages web app with ASP.NET Core: Includes steps on creating the app, adding a model, and implementing validation. Read to learn how to develop a complete Razor Pages web application for managing a database.
🎓Tutorial | Pattern Matching in C# - Embracing Functional Programming: Provides examples of various pattern types and demonstrates how to apply them in different scenarios. Read to learn how to effectively implement pattern matching.
🎓Tutorial | The Anatomy of .NET Aspire Application: Explains how to create and manage a .NET Aspire application. Read to learn how to efficiently build, debug, and manage distributed applications using .NET.
C and C++
Reflection for C++26: Discusses the reflection capabilities proposed for C++26, detailing enhancements from P1240 and the rationale for a single opaque reflection type. Read for practical examples and syntax discussions.
🎓Tutorial | Cooperative Interruption of a Thread in C++20: Introduces the std::stop_token, std::stop_callback, and std::stop_source for requesting a thread to stop. Read to learn how to manage thread interruptions.
Misconceptions about Loops in C: Highlights rare edge cases that complicate loop analysis in static analysis tools. Read to learn about the complexities and potential pitfalls in loop analysis to improve the accuracy of static analysis tools.
Java
🎓Tutorial | Building REST API Using Spring Boot - A Comprehensive Guide: Provides step-by-step instructions covering project setup, data modeling, and more. Read to discover best practices to ensure your APIs are scalable and efficient.
Migrating from Java 8 to Java 17 II - Notable API Changes in Java: Covers enhancements such as new methods for handling null values, collection factory methods, and additions to Optional. Read to ensure a smoother migration.
Thread behavior in the JVM: Covers Java thread basics, lifecycle, extending the Thread class, implementing the Runnable interface, and daemon vs. non-daemon threads. Read to learn the fundamental concepts of threading in Java.
JavaScript and TypeScript
Why Google Sheets ported its calculation worker from JavaScript to WasmGC: WasmGC's optimizations now double calculation speed. Read to learn about the potential of WasmGC to improve web application performance.
Exploring Randomness In JavaScript: Compares Math.random() and Crypto.getRandomValues() for generating random values. Read to learn when to use each for generating random values in JavaScript.
🎓Tutorial | Create npm package with CommonJS and ESM support in TypeScript: Details setting up two configurations and configuring package.json for dual module system compatibility. Read to learn how to ensure broader usability.
Go
7 Common Interface Mistakes in Go: Outlines common mistakes including creating too many interfaces, adding excessive methods, and not writing behavior-driven interfaces. Read to learn how to avoid these pitfalls.
🎓Tutorial | Writing generic collection types in Go - the missing documentation: Addresses two false starts and presents a correct approach using type constraints. Read to understand the importance of combining type constraints.
Rust
🎓Tutorial | Using SIMD for Parallel Processing in Rust: Covers three main approaches: compiler auto-vectorization, platform-specific intrinsics via std::arch, and the experimental std::simd module. Read to learn how to leverage SIMD.
Mako is Now Open Source: Mako is a "fast" and "production-grade" front-end build tool based on Rust, created to address build speed issues. Read to learn about its capabilities, speed improvements, and how to integrate the tool into your projects.
PHP
🎓Tutorial | Using PHP Attributes to Create and Use a Custom Validator in Symfony: Explains PHP attributes and shows how to create validators for mobile numbers and postcodes. Read for examples of applying these validators.
SQL
🎓Tutorial | How to Read and Write from MSSQL Using Pyspark in Python: Provides detailed, step-by-step instructions on performing MSSQL read and write operations using PySpark. Read to learn how to setup, configure, and optimize.
Ruby
Better Know A Ruby Thing - On The Use of Private Methods: Argues that methods without side effects should be public. Read to learn about the trade-offs in using private methods and how to balance encapsulation with usability.
Swift
@Previewable - Dynamic SwiftUI Previews Made Easy: This macro reduces boilerplate code by allowing direct interaction with properties, making previews more interactive and efficient. Read to learn how to use the @Previewable macro.
Kotlin
🎥🎓Tutorial | DataFrame - Kotlin's Innovative Approach to Data Structures: Showcases practical examples, including building a Kotlin Conf app. Read to learn about Kotlin Notebooks, Ktor, and data visualization with Krangl and Kandy.
Flutter
🎓Tutorial | Inspect Flutter HTTPS traffic: Addresses the challenges posed by Dart SDK's lack of proxy support and Flutter's unique certification verification on Android. Read to learn how to set up Reqable to inspect Flutter HTTPS traffic.
Bash
📖Open Access Book | Advanced Bash-Scripting Guide - An in-depth exploration of the art of shell scripting by Mendel Cooper: Serves as a textbook and self-study manual. Read for a comprehensive guide with excercises.
📖 Open Access Book | The Linux Command Line by William Shotts: An extensive guide to mastering the Linux command line, targeting new Linux users. Read to prepare for advanced tasks and system administration.
🌟Food for Thought🚀
The real problems IT still needs to tackle for platforms: Examines the persistent challenges in platform adoption despite platforms like ServiceNow and Salesforce.
The AI Revolution Will Not Be Monopolized: Explores how open-source initiatives democratize AI technology by making advanced tools accessible and transparent.
Empowering Citizen Developers With Low- and No-Code Tools - Changing Developer Workflows and Empowering Non-Technical Employees to Build Apps: Explores how LCNC combine rapid prototyping with traditional coding.
Take the Survey, Get a Packt Credit!
🧠 Expert Insight 📚
Here’s an excerpt from “Chapter 9: Getting to Grips with Combine” in the book, Swift Cookbook - Third Edition, by Keith Moon, Chris Barker, Daniel Bolella, and Nathan Lawlor.
Using Reactive Streams
In this first recipe, we’re going to create a simple SwiftUI view to demonstrate a simple reactive flow. Considering SwiftUI and Combine were released at the same time, it only makes sense to review reactive programming using Apple’s first-party frameworks built specifically for it!
Getting ready
…you’ll need the latest version of Xcode available from the Mac App Store.
How to do it...
With Xcode open, let’s get started:
Create a new project in Xcode. Go to File | New | Project | iOS App. Be sure to choose SwiftUI for the interface.
First, create a view called FetchView that simply holds a Binding property and a body that displays that property’s value:
struct FetchView: View {
@Binding var nameDownStream: String
var body: some View {
VStack(alignment: .center) {
Text("Go fetch the 🎾\(nameDownStream)!")
}
}
}
In ContentView, first add a State property:
@State private var nameStream = ""
Replace the contents of body with Text, TextField, Divider, and our new FetchView, all within VStack:
VStack {
Text("Your Pets Name is: \(nameStream)")
TextField("Enter name", text: $nameStream)
.textFieldStyle(RoundedBorderTextFieldStyle())
Divider()
FetchView(nameDownStream: $nameStream)
}
As you’ll see in Figure 9.1, we have a very basic app layout that uses our nameStream State in multiple sub-views.
Figure 9.1 – A simple yet reactive app!
How it works...
This is a very simple recipe, but it proves a point: reactive programming, especially using Combine and SwiftUI, makes things simpler!
In ContentView, the TextField view is bound to @State property text, which will automatically update any view that points to that property when the user enters text into the field. The Text view is then used to display the entered text, which is updated in real time as the user types. This is an example of a reactive stream where the changes in the input are automatically reflected in the output, without the need for manual intervention.
To further demonstrate a reactive flow, we also added FetchView. By adding a property wrapped with Binding, we essentially declare that we want to subscribe (a key term in reactive programming) to the updates of whatever State property is assigned:
@Binding var nameDownStream: String
Once we set the Text view to use that binding, that view will now reflect the updated value in real time, even though it’s in a different view.
The key takeaway is that unlike in most other paradigms, there was no need for any functions or added logic to take the input and pass it along to the appropriate UI destinations. We simply set the property in the places we expected to input into and output from it. When we run our app, we can begin typing, and our UI reacts accordingly.
The reactive programming paradigm and the Combine framework make it easy to build reactive applications in SwiftUI, allowing developers to write more concise and maintainable code. The combination of SwiftUI and Combine, especially its more advanced features that we’ll learn about in the upcoming recipes, provides a powerful and streamlined way to build reactive UIs in our apps.
The Swift Cookbook - Third Edition was published in June 2024. Packt library subscribers can continue reading the entire book for free. You can buy the book here!
🛠️ Useful Tools ⚒️
Theia IDE: an open-source IDE that offers extensive customization, compatibility with VS Code extensions, and supports a wide range of programming languages.
R2R: an open-source RAG engine for scalable data science development, supporting multimodal file ingestion, hybrid search, and knowledge graph generation, with a RESTful API and a React+Next.js dashboard for user interaction.
whodb: a lightweight, efficient database management tool in GoLang, featuring interactive schema visualization and supporting PostgreSQL, MySQL, SQLite3, MongoDB, and Redis.
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, take the survey, or just leave a comment below.