DEV Community

Cover image for What is shift-left ⬅️ programming?
Gabor Szabo
Gabor Szabo

Posted on • Edited on • Originally published at szabgab.com

What is shift-left ⬅️ programming?

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

Top comments (27)

Collapse
 
jonesbeach profile image
Jones Beach

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!

Collapse
 
syeo66 profile image
Red Ochsenbein (he/him)

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

Collapse
 
jonesbeach profile image
Jones Beach

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.

Collapse
 
eli_mayost_e77aded47b97d9 profile image
Eli Mayost

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

Thread Thread
 
syeo66 profile image
Red Ochsenbein (he/him)

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

Collapse
 
szabgab profile image
Gabor Szabo • Edited

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

Collapse
 
skamansam profile image
Samuel

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

Collapse
 
emi_black_ace profile image
Jacob Van Wagoner

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.

Collapse
 
szabgab profile image
Gabor Szabo • Edited

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.

Collapse
 
ashrobertsdragon profile image
Ashlynn Antrobus

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

Collapse
 
ngdangtu profile image
Đăng Tú

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.

Collapse
 
larbi_gouzal_853466210123 profile image
Larbi Gouzal

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

Collapse
 
larbi_gouzal_853466210123 profile image
Larbi Gouzal

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.

Collapse
 
szabgab profile image
Gabor Szabo

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"

Collapse
 
lsproule profile image
Lucas Sproule

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.

Collapse
 
szabgab profile image
Gabor Szabo

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.

Collapse
 
lamuertepeluda profile image
Info Comment hidden by post author - thread only accessible via permalink
Vito Macchia

The title is a clickbait and all of this you described is pointless without unit and integration test to prevent behavioural bugs and wake up at 2 AM as you described... Alright, having some static type checking surely helps. In the scripting language world, TypeScript is widely adopted over JavaScript because of this, or as another example, there are those (feeble) type annotations in Python, much less used.
However, this is not were Rust shines: it's because of its runtime performances. Although it's much harder to write an enterprise-grade application server in Rust than in other languages. Therefore it's more used for performance-critical code components, firmware, and standalone console applications rather than large web applications.

Collapse
 
the_captain profile image
KS • Edited

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.

Collapse
 
szabgab profile image
Gabor Szabo

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.

Collapse
 
kishore_konjeti_9ac5a9817 profile image
Kishore konjeti

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

Collapse
 
szabgab profile image
Gabor Szabo • Edited

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.

Collapse
 
trenttobler profile image
Trent Tobler

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.

Thread Thread
 
szabgab profile image
Gabor Szabo

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

Collapse
 
manvendrask profile image
Manvendra Singh

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

Collapse
 
motss profile image
Rong Sen Ng

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.

Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more