Posts

Showing posts with the label Rust

From Trait in Rust

Image
From trait in Rust allow types to be created or converted from other types. From trait is used in the rust standard library. It's simple and yet effective. Is common to see From used with Into. However today I want to focus on the From trait. Thinking about coupling point of view you end up coupling 2 or more types, however, in sense of convenience is pretty useful since you dont need to lookup for other structs or external converters. You can use From in order to make it easy to convert from basic types to your types.I have a simple video showing From trait in action. Let's get started!

Type Alias in Rust

Image
Rust is rich in sense of types. You can create your own structs and use generics. Rust even allows you to create a type alias. IMHO type alias is useful for 2 reasons. The first type alias makes the code more readable since the type alias can make the intention more clear. The second and less obvious is when you have generics because you can use the type alias to hide or save typing a big generic expression. However, this is a double edge-sword, at the same time is pretty useful to avoid typing and make the type construct proper it really could be hiding some unnecessary complexity. I have a video showing type alias in action. So let's get started.

Builder Pattern in Rust

Image
Builder Pattern is useful when we need to create complex objects(structs in rust case). Also if you want to do a fluent DSL Builder is a useful pattern for that as well. Today I will show how we can implement this Pattern in Rust, so I have a simple POC to show and also a video. So Let's get started! 

Concurrency in Rust

Image
Rust has amazing support for concurrency programming. Today I will cover Mutex, Rc, RefCell, Channels, and Threads. I might make a second post covering the rest of the concepts like Arc. Rust dont have green threads since focus on having zero cost of abstractions. However, using channels we have a powerful abstraction to work with threads. Combined with Rc/Arc and RefCell/Cell we have a good foundation for good concurrency programs. Today I want to share 4 small pocs and 4 videos about Mutex, Rc/RefCell, Threads, and Channels in Rust. Let's get started!

Add trait in Rust

Image
Rust has this interesting trait called Add  which allows us to use the + operator and add 2 structs together. This is very useful for numeric types but also for engineering productivity lets say you are building a DSL for instance or an internal DSL. So I made some implementation and a video - Let's get started!

Closures in Rust

Image
Rust allows us to do functional programming. One important thing in FP is being also to pass functions as parameters and also return functions which are also called high Order Functions. Today I want to share 2 videos and 2 pocs showing how we can do High Order Functions in Rust also you will get currying for free :-). I also will show how we can do closures using traits as well. So Let's get started!

Simple Dummy Clojure Parser in Rust

Image
This is not a production-ready neither serious parser, it's for pure fun! I was bored during one of the pandemics late nights watching Sam Rose's 3h parser video . So I decided to do something similar, inspired by Sam's video. Of course, I did not want to make a 3 hours video fighting Rust compiler - which is the ultimate reality but something shorter. The code is similar but I have few more operations like * and inc.  I also using a queue for Args not Stack so we can preserve ordering. So this is a cool way to learn rust because in the code we will be using Stack and Queue Data Structures and basics of borrow and ownership in rust. Let's get started!

Vector in Rust

Image
Vector is a core collection in Rust. Vector(Vec) can be used for storing a list of values or even if you need a Stack - it's your data type. Rust language is pretty fast and secure however dealing with borrowing, ownership, and lifespan lifecycle is a high wall that often you can bash your head pretty hard against it. Returning Vecs and passing them as parameters could be pretty challenging if you were new to Rust. Strings also are pretty challenging in Rust. So today I want to share a video doing common operations with Vecs but always using functions and passing Vecs and Receiving Vecs. Hopefully, this will be useful in your common and daily work with Rust. Let's get started!  

Rust Parser and State Machine

Image
Rust it's a very nice and powerful language. I believe Rust has a place beyond systems and hardware programming. I personally believe we will be seeing more and more Rust in the following years just like Go took some time to liftoff I believe Rust time is yet to come. Rust it's powerful because favors safe programming not only in sense of memory management but also combined with functional programming we can get the best of all words meaning: Safety, Productivity, Less code, Doing more with less, reducing complexity, and leverage engineering best practices. Today I want to show how easily we can write a cyclic state machine parser with Rust and without using any crates but really 100% on the standard language.  So Let's get started.

GraphQL Server With Java & Clients in Go and Rust

Image
GraphQL it's an interesting approach for Data Aggregation. GraphQL is a query language API for existing data. You can leverage all your REST APIs and existing data sources. GraphQL it's mobile-friendly and you can ask literally just the fields you need. GraphQL also allows you to share queries and there are clients for pretty much all languages. GraphQL allows you multiplex and de-multiplex multiple requests in one, being really great for tail latency and nice for data-intensive applications. However, not everything in graphql is flowers and I dont want to paint a rosy picture. There are issues and tradeoffs you need to take into account. I highly recommend you read these 3 series of posts I made comparisons with other approaches like BFs. BFF and GraphQL Dilemma part 1 , part 2 , and part 3 . Today I want to share a video I made where there is a GraphQL Server written in Java and we have 2 clients one Written in Go Lang and the other written in Rust. So Let's get started....

timetracking-rs: Tracking Hours in Rust

Image
I worked with Technology for a long time. I created a Python script 10 years ago to manage my working hours for control, observability, backpressure purposes. Last Friday night(What a nerd thing to do, I know), I re-wrote this script into a Rust program. I always like to build my own tools, for several reasons, like make my work more productive or just because I want an excuse to do something useful for me in a language that I liked. It took me about 4h to figure out how to do this in Rust. There were 2 basic challenges with was Strings(OH I hate Strings in Rust) and working effectively with Data/Time math operations. I would 2 hours figure it out and making this work and 2 other hours refactoring the code to make it better. Overall code with Rust is pretty productive and fun however Strings and pain in the ass. So I'm using this program every day (decommission my old python script) - so this might be useful for you too. Let's get started.

Having fun with Rust

Image
I',m in love with Rust ðŸ’“ since 2018. Last year I spend a great amount of time architecture and designing systems with Rust and also Learning and coding. Here are some of my POCs . I've also done several posts about Rust . So this is another one, today I want to show another lick ass things you can do with Rust. No need to say that Rust is Fast and kicks ass but today I will show so cool code I was doing with Rust by coding some Euler with Rust and Java, In comparison, some stuff in Java is actually is better than rust but most of the things are better in Rust. It takes some time to get used to Rust but once you do you will see that the Compiler is just completely amazing and helps a lot. I',m coding rust with VSCode editor thanks to RLS .  One of the features I want to show you guys is called If Let and for me is a killer feature it's super cool.  So let's get started!

Struct and Traits in Rust

Image
Rust is not an OOP language. However, is possible to have similar behavior using Structs and traits. Traits are great because allow us to create common and interfaces and allow structure for generic coding. The struct is like a struct in C. They allow us to have Pojos and hold both data and behavior using traits.  Today I want to show you guys how we can work with struct and traits in Rust. This is another short video focusing on understanding and also you will learn somethings about macros as well.  So I hope you guys liked it, let's get started !!!

Result & Pattern Matcher in Rust

Image
It's common in the software language community to worry about the "idiomatic" way of doing this. So what's the idiomatic or rust way to do things. It's easy to learn new languages and continue with old mindsets coming from C or Java for instance.  IMHO Readability, High Cohesion, Loosely coupling, Debugability, Good Design are super important aspects in regards to you are idiomatic or not. But being idiomatic is like following a standard and makes things easier for all engineers. For this blog post, I want to share a video I recorded on using 2 resources in Rust called Pattern Matcher and Result. These mechanisms are not unique to Rust, actually, they are functional programming concepts.  The result is also known as a Monad and you can find it in Haskel, Java, Scala,  and several other languages, with different names like Either, Maybe, Option, Optional and so on and on.  Pattern matcher is also found in lots of languages like Haskell and Scala.

Borrowing and Ownership in Rust

Image
Rust is a pretty interesting language. I said that not because of unique performance but also because it makes you think differently. Languages that make you think differently are great even if you dont use them in production. Rust is quite unique because it does not have Runtime like Java and neither a traditional Garbage collection. Rust managed to be efficient thanks to its's smart compiler and some new rules like Borrowing and Ownership. So I recorded a quick video to explain how Borrow and Ownership work in practices. I hope you like and have fun learning Rust.  Let's get started!

Running a rich Microservice constellation in Kubernetes

Image
Languages have trade-offs like any solution in tech. Microservices are great for many reasons, one of them allows the best tool for the job. Kubernetes allows us to have the same operational standards and procedures even using different languages and solutions. For this blog post, I want to show a simple project I build which is a constellation of services. There are 5 microservices, written in several languages like Scala, Java, Go, Python and Rust. The services do a pretty basic math operation like (+, - , / , *) and the Scala one does the aggregation and orchestrate the other services using a polish notation algorithm and REST calls.

Rust 101

Image
Rust is a kick-ass language. Many developers hate Rust because of borrowing and responsibility rules, I get it. However, these rules that make the language so appealing and much more efficient, check it out Discord use case , they migrated from Go to Rust. Today I want to show some nice things that the language offers to any engineer who wants nothing by the best performance. Rust syntax could be better? Yes, for sure. However syntax it's not what matters most. So let's get started, I made a video for us show in practice some cool stuff about Rust, I hope you like it.

Actix(Rust) it's blazing fast

Image
I'm a performance aficionado. I always will be :-). However, performance is a tricky thing. It always depends on the use case. There are several things could affect a benchmark like: * Hardware * Payload size * Kind of Operation * Time * Configurations / Tunings * Warm-Up * What the code does and how I never like the blind discussions saying this server is always better than that server because I knew use cases are everything. Performance is important and in the cloud, it leads to other things like Scalability and Costs. Great performance allows better scalability, therefore it reduces costs because you do more with fewer resources(machines or containers).

The dark side of Rust Language

Image
Rust is an amazing language. If you follow my blog activity and know me in person you might know I'm really invested in rust on the last +12 months and also blogging a lot about Rust. Now I want to do something different. I do not want to paint a rosy picture of Rust. I do believe trade-offs matter and you only know something true when you know the cons. There are some problems I will expose in this blog post and not related to rust only but related in fact about two other factors. A) "New" languages. Rust has +10 years however still not mainstream and I still consider it a new language. B) New Paradigm / Approach - everything you deviate from standard C/OOP you will face resistance, I saw it happens a lot with other languages like Scala and Clojure. These problems happen in rust but I want to make it absolutely clear they are not unique to rust. So Let's get started, let's start with the Good things.

Building a Microservice with Rust

Image
Rust is a great language, currently was the language that I most study in 2019 and in 2020(so far). Rust has interoperability with any language pretty much. Rust is also great for containers and to run in Kubernetes. Today I want to show how to build a simple microservice. We will use Actix , Tokio-Postgress , and other libraries. We will use Postgress as our source of truth and we will run it in docker(for development sake). We also will use Barrel + some customs migration structure I created. The code will be all async and non-blocking IO. I hope you have fun, let's get started.