ProgrammingPro #74: Swift 6 Concurrency, C++ Memory Safety, Python Concurrency Best Practices, and Rust for Linux
Join Roman Lavrik from Deloitte at Snyk hosted DevSecCon 2024
Snyk is thrilled to announce DevSecCon 2024, Developing AI Trust Oct 8-9, a FREE virtual summit designed for DevOps, developer and security pros of all levels. Join Roman Lavrik from Deloitte, among many others, and learn some presciptive DevSecOps methods for AI-powered development.
@{mv_date_MMM d, yyyy}@
Hi @{First Name}@,
Welcome to this week’s edition of ProgrammingPro!
In today’s Expert Insight, we bring you an excerpt from the recently published book, Generative AI-Powered Assistant for Developers, which demonstrates how Amazon Q Developer assists in generating C++ code (The book also covers Python, Java, SQL, and more) for complex tasks like developing an operating system kernel.
News Highlights: Swift 6 adds strict concurrency checking, C++ interoperability, and Embedded Swift; 60% of open source maintainers are unpaid, says 2024 report; C++ Alliance proposes a Safe Standard Library for memory safety; and RustConf reaffirms Rust's role in the Linux kernel.
My top 5 picks from today’s learning resources:
But there’s more, so dive right in.
Stay Awesome!
Divya Anne Selvaraj
Editor-in-Chief
PS: This month’s survey is still live. Do take the opportunity to tell us what you think of ProgrammingPro, request learning resources, and earn your one Packt Credit for this month.
Use AI to 10X your productivity & efficiency at work
Still struggling to achieve work-life balance and manage your time efficiently?
Join this 3 hour Intensive Workshop on AI & ChatGPT tools (usually $399) but FREE for the first 100 people.
Save your free spot here (seats are filling fast!) ⏰
🗞️News and Analysis🔎
Swift 6 now available with strict concurrency checking: The version expands platform support, adds C++ interoperability, offers Embedded Swift, and improves build performance on Windows.
Java 23 is now available: The version introduces preview features such as primitive types in patterns, flexible constructor bodies, and module import declarations. Library updates include structured concurrency and more.
The state of open source maintainers: The 2024 State of Open Maintainer report has revealed that 60% of open source maintainers are unpaid despite their critical role in software security and paid maintainers face stress.
Can Java rival Python in AI development?: Experts argue that Java's performance, enterprise adoption, and evolving syntax position it for growth in AI.
C++ Alliance takes aim at C++ memory safety: The Safe C++ Extensions proposal introduces a Safe Standard Library with memory-safe implementations and features to prevent common memory-related errors.
ASP.NET Core 9 RC 1 - Keep-Alive Timeouts for Websockets, Improved SignalR Tracing, and MoreLike: Other updates include Linux support for HTTPS certificates and type overriding for InputNumber components.
RustConf speakers affirm Rust for Linux project despite challenges of unstable Rust, maintainer resignation: The Rust for Linux project, aims to make Rust a second programming language for the Linux kernel.
🎓Tutorials and Learning Resources💡
Python
Why Learn Python Concurrency: Explains how concurrent, parallel, and asynchronous execution allow programs to fully utilize modern hardware, improve performance, and scale more effectively.
For more Python resources, go to PythonPro
Recent Python Books from Packt
Buy 5 eBooks for 30% + 20% off!
Discount automatically calculated when you add items to cart
Get the eBook for $31.99 $21.99
Get the Print Book for $39.99 $29.98
Get the eBook for $43.99 $29.99
Get the Print Book for $54.99 $40.99
Get the eBook for $31.99 $18.99
Get the Print Book for $39.99 $25.99
Print book discounts end on the 22nd of September 2024.
C# and .NET
🎓Tutorial | Using the Pinecone vector database in .NET: Explains how to build retrieval-augmented generation (RAG) AI applications.
You have 10 seconds to nixify your .Net project: Guides you through building, packaging, and containerizing .NET applications using Nix and provides a detailed example.
🎓Tutorial | Logistic Regression with Batch SGD Training and Weight Decay Using C#: Teaches you to use logistic regression for binary classification tasks and interpret the significance of model weights and bias.
C and C++
An Overview of C++26: Concurrency: Focuses on the new std::execution framework for managing asynchronous execution with schedulers, senders, and receivers.
Going Super Sonic with Asio: Covers core usage, thread management, concurrency, IO optimization, and advanced strategies like custom allocators, disabling Nagle's algorithm, and efficient buffering.
🎓Tutorial | LS implementation: Explains the implementation of the
ls
command in Unix-like operating systems, detailing how to replicate its various functionalities in C, such as listing all files (including hidden ones), and more.
Java
🎓Tutorial | Exception handling in Java - The basics: Covers how to throw, try, catch, and clean up exceptions and introduces concepts such as checked and unchecked exceptions, error handling, and the use of
finally
blocks.Embracing Reactive Applications on JVM - A Deep Dive Into Modern I/O Models and Vert.x: Discusses the evolution of I/O models and how reactive architectures, particularly Vert.x, can be leveraged for modern software development.
The Arrival of Java 23: Announces the release of Java 23, detailing its new features, performance improvements, and contributions from the Java community while highlighting its significance for modern development.
JavaScript and TypeScript
Compile and run C in JavaScript: Introduces Bun's new feature in version 1.1.28, enabling developers to compile and run C code directly from JavaScript for efficient use of native libraries without relying on N-API or WebAssembly.
🎓Tutorial | How To Detect Proxies: Outlines how to detect and block proxy-based signups in web applications by examining IP spoofing techniques, using the X-Forwarded-For header, WebRTC, and third-party APIs like IPQuery.
The Strange Behavior of the void Type in TypeScript: Explores the peculiar behavior of the
void
type in TypeScript, explaining its primary use for function return types, its restrictions on variable assignments, and more.
Go
How Go Tests "go test": Explains how the Go team tests the
go test
command, outlining the evolution of testing methodologies for command-line tools, from shell scripts to Go-based testing frameworks.Notes on running Go in the browser with WebAssembly: Covers topics such as calling Go functions from JavaScript, manipulating the DOM with Go, and using TinyGo for smaller binaries.
Rust
Understanding Memory Ordering in Rust: Explores the concept of memory ordering in Rust in multi-threaded programs to ensure data consistency when compiler and processor optimizations could disrupt execution order.
🎓Tutorial | Let’s build and optimize a Rust extension for Python: Covers creating a Rust extension using PyO3 and Maturin, and optimizing it through various techniques like link-time optimization, and faster random number generation.
Swift
Swift Build Times and Module Verification: Discusses optimizing Swift build times for the app Secrets 4 by refactoring its codebase into 36 smaller modules for better compiler performance and clearer access control.
🎓Tutorial | Using Traits to annotate and customize test behavior: explains how to use traits in Swift Testing to annotate, customize, and control test behavior, including conditional enabling/disabling, bug tracking, and time limits.
PHP
🎓Why I Avoid Using empty() in PHP? A Closer Look: Highlights how the function's broad handling of values like 0, "0", and false can lead to unexpected behavior in production code, and advocates for strict comparisons (===).
SQL
🎓Tutorial | SQL from a Programming Language Perspective — Part I: Explains SQL's core operations—filtering, projecting, grouping, sorting, and merging tables—and how queries are built, focusing on SQL’s syntax evolution.
Ruby
🎓Tutorial | Ruby 3.0 - Optimizing Applications with GC.compact: Discusses the GC.compact method, which reduces memory fragmentation in long-running applications by compacting the heap.
Kotlin
🎓Advanced Kotlin Flow Cheat sheet (for Android Engineer): Covers key concepts such as cold vs. hot streams, channels, flow operators (merge, combine, zip), and buffer handling, with practical examples for optimizing flow.
🌟Best Practices and Advice🚀
Leveraging eBPF for Improved Infrastructure Observability: Discusses how Netflix uses eBPF to enhance infrastructure observability by monitoring system performance and detecting "noisy neighbors."
Llama 3 in Action - Deployment Strategies and Advanced Functionality for Real-World Applications: Provides insights into deploying Llama 3, optimizing performance on platforms like AWS, and fine-tuning models for specific cases.
Safeloop Architecture: Introduces a coding style focused on reducing cognitive load and improving predictability between design-time and runtime behavior by using explicit, predictable code patterns.
A Comprehensive Introduction to Git & GitHub — Part 1/4 - Core git features: Covers essential concepts like Git architecture (working directory, staging area, repository), installation, configuring user identity, and more.
🧠Expert Insight📚
Here’s an excerpt from “Chapter 5: Boost Coding Efficiency for C and C++ with Auto-Code Generation” in the book, Generative AI-Powered Assistant for Developers by Behram Irani and Rahul Sonawane, published in August 2024.
End-to-end C++ language use case development
Now let’s move to the sample use case to show the power of Amazon Q Developer’s ability to recommend code. To illustrate, I am going to use the VS Code script editor window with single
and multi-line prompts.
Let’s say that we want to write a C++ program to develop a new operating system kernel, which can control system resources and has the ability to handle complex memory management tasks. The kernel must interact with hardware, manage processes, and ensure stability across different hardware architectures.
Let’s use the multi-line prompt technique to achieve the preceding use case.
Prompt:
/* Write an end to end executable C++ script
to develop a new operating system kernel, that can control over system resources and ability to handle complex memory management tasks. The kernel must interact with hardware, manage processes, and ensure stability across different hardware architectures.
*/
Figure 5.11 – Writing a C++ program with Amazon Q Developer
The preceding screenshot shows partial code suggested by Amazon Q Developer. You can observe that end-to-end code demonstrates several fundamental and advanced concepts in C++ programming, including OOP, classes, vectors, functions, error handling, and more.
Now let’s use an interactive inline prompt with the chain-of-thought technique to enhance the code. As you can see, the loadProcess()
function does not have exception handling, so let’s instruct it to add an exception handle for the null process with the single-line prompt technique:
Prompt :
/* add exception handling for loadProcess */
Figure 5.12 – Prompt – C++ program sample snapshot
As shown in the screenshot, based on our prompt, Amazon Q Developer added a nullptr
condition to check the process load exception. If it encounters a null pointer, then the code gracefully exits with a Error: process is
null
message.
Generative AI-Powered Assistant for Developers was published in August 2024. Packt library subscribers can continue reading the entire book for free or you can buy the book here!
Get the eBook for $31.99 $21.99
🛠️Useful Tools⚒️
GraalVM: a high-performance JDK that compiles Java applications into native executables for instant startup and efficient performance.
void: an open-source Cursor alternative, forked from vscode, allowing users to build, contribute, and develop independently with support via Discord and email.
Neosync: an open-source tool for anonymizing PII, generating synthetic data, and syncing environments to improve testing, debugging, and compliance.
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.