What is shift-left ⬅️ programming?
Gabor Szabo

Gabor Szabo @szabgab

About: Helping individuals and teams improve their software development practices. Introducing testing, test automation, CI, CD, pair programming. That neighborhood.

Location:
Israel
Joined:
Oct 11, 2017

What is shift-left ⬅️ programming?

Publish Date: Dec 17 '24
80 28

Rust 🦀 is the ultimate shift-left programming language!

If Shift-left testing means that we introduce testing earlier in the life-cycle of software development then shift-left programming is using a programming language that will find you (potential) bugs 🐛🐛🐛🐛 earlier in the life-cycle of the development process.

The dynamic programming languages such as Python, Perl, Ruby, PHP, and of course JavaScript are very flexible, but it also means that we find out about a lot of issues only during run-time.

Compiled languages such as 🇨 C, C++, Java ☕, and Rust are much stricter. The code won't even compile if you don't define the types of your variables properly.

For example

🐪 Perl does not care much if a value is a number like 42 or if it is a string that looks like a number like "42".

🐍 Python already cares about this, but it will find out that you are trying to add a number to a string only during run-time.

🇨 ☕ C, C++, Java, and 🦀 Rust won't even compile with code where we try to add a variable holding a number to a variable holding a string.

That is, we find out about our mistake sooner than later.

Rust takes this to the next level and prevents you from making all kinds of mistakes. Mistakes that in other compiled languages you'd only notice at 2 am when the system suddenly stops working in a mission critical application.

No it won't protect you from all the mistakes. In particular it won't protect you from bugs 🐛🐛🐛 in you logic and algorithm. If you put a + sign somewhere where you should have but a - sign you will still get the wrong results, but Rust has moved the programming world more to the left (earlier).

😺 So if you are wondering what is the value of Rust then it is that you can write fast code (like C, C++) that is free from a lot of memory related-errors that you might encounter in C or C++.

It helps you find bugs 🐛🐛🐛 earlier in the development process, thus saving you time and money in the whole process.

Correction

Java handles "23" + 19 by converting the latter to a string and then doing concatenation.

Live online presentations

I run live online presentations about Rust. You are invited

Comments 28 total

  • Jones Beach
    Jones BeachDec 17, 2024

    One of the first students I ever mentored said to me, "With Rust, when the code compiles, it just works!" I hadn't heard of the phrase "shift-left programming" but it TOTALLY applies to Rust!

    • Gabor Szabo
      Gabor SzaboDec 18, 2024

      I just made the term "shift-left programming" up, but I think it fits the idea.

    • Red Ochsenbein (he/him)
      Red Ochsenbein (he/him)Dec 18, 2024

      "With Rust, when the code compiles, it just works!"
      I call BS. Yeah, it just works... without guarantee it actually does what it should.

      • Eli Mayost
        Eli MayostDec 18, 2024

        The only guarantee, is that it does what you ask it to do...

        • Red Ochsenbein (he/him)
          Red Ochsenbein (he/him)Dec 18, 2024

          Computer always do what you tell them to do, but never what you wanted them to do. 😅

      • Jones Beach
        Jones BeachDec 18, 2024

        lol, imagine if I told my student 'I call BS' during their moment of celebration? I was just happy they were seeing the value in Rust and its guarantees.

  • Kishore konjeti
    Kishore konjetiDec 18, 2024

    How about Go Lang. It has all strength of compiled and strict typing.

    • Gabor Szabo
      Gabor SzaboDec 18, 2024

      Go has a different set of features, a different set of trade-offs.

      Go is said to be simpler to learn and use than Rust, but it is also about 3-5 times slower than Rust according to this benchmark

      Go also has a Garbage Collector which makes it unfit to a set of applications where you cannot have pauses in the operation.

      • Trent Tobler
        Trent ToblerDec 25, 2024

        Any language with dynamically allocated memory can have pauses in their execution due to memory reclamation.

        Example - suppose you have a graph of 1 billion interconnected allocated nodes describing a large directed graph. When you free the root maintaining the accessibility to all that data, a manually memory managed language will need to call "free()" or "delete" or whatever mechanism releases that memory 1 billion times. This will induce a pause while this runs.

        A GC language can potentially reduce that pause, depending on architecture and whether it can do concurrent GC while program logic continues to run while memory is being reclaimed.

        • Gabor Szabo
          Gabor SzaboDec 26, 2024

          This sounds like a rather special case, but I wonder, how do you handle such cases in c, to avoid the long pause?

  • АнонимDec 18, 2024

    [hidden by post author]

  • Samuel
    SamuelDec 18, 2024

    What are your thoughts on "backtyping" - adding types to non-typed languages? Do you think that might left-shift a bit as well?

    • Gabor Szabo
      Gabor SzaboDec 18, 2024

      Certainly. For example the type annotation of Python is quite good. If you don't forget to run mypy. See my recent post about it and as I understand the whole idea behind TypeScript was to add a type-system to JavaScript.

      • Ashlynn Antrobus
        Ashlynn AntrobusDec 18, 2024

        If you install MyPy as a plugin for VSCode, it runs in realtime, and you get static type checking as a linting tool.

        I'm a big fan of realtime results, which is why I tend to prefer scripting languages over compiled ones. That's left shifting to me

    • Jacob Van Wagoner
      Jacob Van Wagoner Dec 19, 2024

      That was exactly the point of TypeScript -- to solve and prevent "oops, wrong type!" mistakes in browser code (which can only be JavaScript) without having to force browsers to run anything but JavaScript.

  • Đăng Tú
    Đăng TúDec 18, 2024

    At first I thought you mean left shift << operator... then I feel like it was about strict type.

    Anyway, I feel sorry for dev coming from rtl language background... in case it is you who reading this comment. Ppl who read from left to right think left is start, so shift-left, you know. Is quite lazy way to making a proper name.

  • Larbi Gouzal
    Larbi GouzalDec 18, 2024

    I was very curious as a java developer in how rust do this things, but you didn't give any examples.

    • Larbi Gouzal
      Larbi GouzalDec 18, 2024

      Because in the example you give adding a number to a string is not a bug per se. As + in java is an overload operator for strings that is working for concaténation and the result is always a String object not a number.

      • Gabor Szabo
        Gabor SzaboDec 19, 2024

        I just checked the Java thing and added a correction to my post.

        Rust would require you to convert either one to the type of the other before using the + operator. e.g. 23.to_string() + "19"

  • Rong Sen Ng
    Rong Sen NgDec 19, 2024

    Rust has shift left or whatever term used in making your code safer built-in in the language. That's why you don't need so many fancy terms.

  • Lucas Sproule
    Lucas SprouleDec 19, 2024

    I understand somewhat what you are trying to say here, but it doesn't really remove the need for tests. It's similar to golang right. Golang always forces you to deal with errors, but I still need to test. I agree, typescript, for example when a request comes in and I tell it it will be a type user typescript will believe me even if it's a lie. Golang with unmarshalling will throw an error. That's certainly ideal. However, I should still test the code.

    • Gabor Szabo
      Gabor SzaboDec 19, 2024

      Of course you still need to test the logic and algorithm. Thank you for emphasizing that.

      If you would like to compare Go and Rust then I think the two main differences are that Rust is about 3-5 times faster and it does not have a GC.

  • Manvendra Singh
    Manvendra SinghDec 19, 2024

    That is why one should opt for TypeScript when working with JavaScript code, be it on server or browser.

  • АнонимDec 19, 2024

    [hidden by post author]

  • KS
    KSDec 19, 2024

    Can you give an example of an error which causes compiled languages to stop working whereas Rust won't be affected ?

    Rust takes this to the next level and prevents you from making all kinds of mistakes. Mistakes that in other compiled languages you'd only notice at 2 am when the system suddenly stops working in a mission critical application.

    • Gabor Szabo
      Gabor SzaboDec 19, 2024

      C and C++ are notorious for memory handling errors. e.g. stack overflow (not the web site :-) or memory leak when the developer forgets to free memory.

      Rust also help by preventing - at compile time - a lot of issues with threading.

  • АнонимDec 19, 2024

    [hidden by post author]

  • Well Me Right
    Well Me RightDec 23, 2024

    Good post!

Add comment