The C "if" expression can do anything — assignments, comma-separated sequences, even multiple side effects — and the compiler quietly uses only the last value to decide the condition. It works, but it’s subtle, confusing, and can hide bugs. Rust takes a safer approach: it uses block expressions to evaluate statements left-to-right, preserves side effects, but forces the last expression to be a boolean. Flexible vs safe — the choice is clear. #CProgramming #RustLang #ProgrammingTips #CodeSafety #SystemsProgramming #SoftwareEngineering #CodeOptimization #ProgrammingLanguages #DeveloperInsights #TechTips
Rust vs C: Safe Block Expressions vs Subtle Conditionals
More Relevant Posts
-
Compiler Construction sounded cool. Then I actually tried building one. I started with the first stage: a Lexical Analyzer built from scratch using C and Flex, with a Harry Potter–inspired syntax (numspell, truthcharm, beginmagic). At first, matching tokens with regular expressions felt straightforward. Then the problems started. Valid-looking code broke. Invalid code slipped through. That’s when I realized: a lexer that isn’t strict is useless. So I focused heavily on error detection and reporting, making the lexer explicitly catch: • Digit-prefixed identifiers (5abc) • Unterminated strings and comments • Invalid number formats It doesn’t just tokenize the magic — it rejects broken spells. This was my first real lesson in compilers: being precise matters more than being permissive. 🔗 GitHub Repo: https://lnkd.in/dBeeViyZ #ComputerScience #CompilerConstruction #Flex #CProgramming #CSStudent #CodingJourney
To view or add a comment, sign in
-
-
Why can’t you index a string in Rust? If you’ve ever written `my_string[0]` and hit a compiler error, you’re not alone. This isn’t a Rust limitation — it’s a deliberate design choice. Rust strings are UTF-8 encoded, which means: • Characters are variable-width • Indexing would be misleading and unsafe • Performance guarantees would break In my latest video, I explain: – Why Rust forbids string indexing – How UTF-8 actually works under the hood – The difference between `String` and `&str` – The correct and idiomatic ways to work with strings This is part of my Rust debugging series focused on real pain points developers face when transitioning to Rust. 👉 Video link in the comments. #Rust #RustLang #RustProgramming #SystemsProgramming #MemorySafety #UTF8 #SoftwareEngineering #Programming
To view or add a comment, sign in
-
🚀 C++26 : The JSON Evolution Writing a JSON parser has historically been a chore. You either use a heavy library or write tedious mapping code for every single struct. C++26 is set to change the game with Static Reflection (P2996). Here is how the "JSON-to-Struct" evolution looks: 📢 Note: This code demonstrates the proposed C++26 Reflection syntax (P2996). Since the standard is still evolving, some technical details or keywords may change before the final release #cpp #programming #cpp26 #coding #softwareengineering #cleancode
To view or add a comment, sign in
-
-
Algorithm Challenge – Level 3 | #33 | Vowel Counting in Strings In Algorithm Challenge #33 (Level 3), I implemented a C++ solution that counts the number of vowels within a user-provided string. This challenge is a natural progression from Challenge #32. Previously, the focus was on validating a single character. Here, the same validation logic is reused and applied at scale across an entire string. From a software engineering perspective, the key takeaway is clear: Well-designed logic should be reusable, not rewritten. By isolating the vowel-checking rule into a dedicated function and combining it with controlled string traversal, the solution remains clean, maintainable, and scalable—exactly the approach used in real-world text processing systems. Clear rules. Reusable logic. Scalable thinking. Full implementation available on GitHub: 👉 https://lnkd.in/dv6urFPg 🏷️ Tags #AlgorithmChallenge #SoftwareEngineeringConcepts #SoftwareEngineering #CodeReuse #ScalableDesign #StringProcessing #Algorithms #EngineeringPrinciples #CleanCode #ComputerScience #DeveloperMindset #Programming #ProgrammingDiscipline #ProblemSolvingSkills
To view or add a comment, sign in
-
Debugging is not just about fixing code — It’s about realizing that the problem was never the system, the compiler, or the language… It was your own logic all along. 😅💻 Each bug becomes a lesson and every mistake pushes you to think a little deeper and smarter. #MondayMeme #Debugging #CoderLife #ProgrammingHumor #CQSTCollege #CQST #CQSTPanipat
To view or add a comment, sign in
-
LeetCode is HARD until you Learn these 15 Patterns: 1. Prefix Sum 2. Two Pointers 3. Sliding Window 4. Fast & Slow Pointers 5. LinkedList In-place Reversal 6. Monotonic Stack 7. Top ‘K’ Elements 8. Overlapping Intervals 9. Modified Binary Search 10. Binary Tree Traversal 11. Depth-First Search (DFS) 12. Breadth-First Search (BFS) 13. Matrix Traversal 14. Backtracking 15. Dynamic Programming Patterns
To view or add a comment, sign in
-
-
💎 C++23: Practical Tools for Modern Development Reflections on Alex Dathskovsky ☕ Talk at Meeting C++ 2025 While many developers are still transitioning to C++20, C++23 is already stable and offers a set of "quality of life" improvements and performance optimizations that make it worth the jump. In his talk, Alex Dathskovsky ☕ argues that if you aren't constrained by legacy automotive standards (like MISRA), there is no reason to stay on C++17 in 2026. 📢 Conclusion Alex Dathskovsky ☕ message is clear: C++23 isn't just a minor update; it’s about making the language safer, faster, and more expressive. By removing "divergence" (weird edge cases where the compiler doesn't do what you expect), C++23 allows developers to focus on logic rather than language quirks. Alex Dathskovsky ☕ doesn't just give overviews; he dives deep into performance and explains how changes affect the resulting assembly code. 🧠 💎 Special thanks to Alex Dathskovsky ☕ for his contribution to the language's development! These talks help the community quickly adopt modern standards and write higher-quality code. 📺 Watch here: https://lnkd.in/dAXdM-WP #Cpp23 #Programming #SoftwareDevelopment #MeetingCpp #ModernCpp #Coding #Performance
To view or add a comment, sign in
-
-
A naked function is a function where the compiler is instructed not to generate the usual prologue and epilogue code (no stack frame setup, no register saving, no automatic return), leaving all ABI and control-flow responsibilities to the programmer. One of the clearest philosophical differences between C++ and Rust shows up in how they handle naked functions. In C++, you can mark a function as __attribute__((naked)) and still write normal-looking C++ like int f(int x) { return x + 1; }. On x86-64 this may appear to work because arguments are passed in registers, but switch to -m32 and the illusion breaks immediately: the compiler still assumes a stack frame exists and happily emits mov eax, [ebp+8], even though ebp was never initialized. The result is silent undefined behavior that only shows up under a different ABI, optimization level, or architecture. Rust deliberately refuses to allow this class of bug. While Rust does have #[naked], it’s unstable, unsafe, nightly-only, and enforces assembly-only bodies—no parameters, no locals, no Rust expressions, no implicit returns. If you try to write logic like x + 1 in a naked function, Rust simply won’t compile it. This isn’t about being restrictive; it’s about making ABI violations explicit instead of accidental. C++ trusts you and lets UB slip through quietly. Rust forces you to be loud, deliberate, and honest when you step outside the abstract machine. #Cplusplus #RustLang #SystemsProgramming #LowLevelProgramming #UndefinedBehavior #CompilerDesign #ABI #OperatingSystems #KernelDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
In C++, it’s possible to modify a const variable using const_cast or raw pointers, but doing so results in undefined behavior—the compiler is free to assume the value never changes, and optimizations can silently break such code. Rust takes a much stricter approach: in safe Rust, modifying immutable data is impossible, there is no equivalent to const_cast, and mutating through an immutable reference is forbidden. If mutation is truly required, Rust forces developers to make that intent explicit through mechanisms like Cell, RefCell, or UnsafeCell inside unsafe blocks. This design eliminates an entire class of subtle, optimizer-dependent bugs common in low-level C++ code and shifts the tradeoff toward correctness and maintainability without hiding the cost or risk of unsafety. #Rust #Cplusplus #SystemsProgramming #Compilers #LowLevel #SoftwareEngineering
To view or add a comment, sign in
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development