rustips How to print your Structs the way you want it

How to print your Structs the way you want it

The Struct Let’s keep it simple here with a struct for a 2D Point in space: pub struct Point { x: i32, y: i32 }   1st (fail) try If you try to print an instance of your struct you will get a panicked compiler let p = Point{x: 10, y: 5}; println!(“{}”, p); error[E0277]: …

Read Article Read More

rustips Convert user input to Numeral

Convert user input to Numeral

Input to Numeral This method is useful when the expected input will contain a simple number. If you have to parse the sentence for the number, this is not the method you should be using. let mut num1 = String::new(); println!(“What is the first number? “); stdin().read_line(&mut num1).expect(“Invalid input”); let num1: i32 = num1.trim().parse::<i32>().expect(“We’re expecting a number”); …

Read Article Read More

rustips Get user input as text

Get user input as text

Input as text use std::io::stdin println!(“What is your name?”); let mut name = String::new(); stdin().read_line(&mut name).expect(“Couldn’t read the line”); println!(“Hi {}!”, name); What is your name? John Hi John! We needed: to import the standard input module (stdin) create a mutable variable to serve as the buffer for the reader and hold the user’s answer …

Read Article Read More

rustips Print in same line

Print in same line

“Normal” Print If you want to print with a line break at the end, it is pretty easy: println!(“Here is your message!”); println!(“With {} placeholders too!”, 1); Which would output: Here is your message! With 1 placeholders too!   Print in the same line This needs some more increments. We need to import some things …

Read Article Read More

pattern Singleton Pattern – Creational

Singleton Pattern – Creational

The Singleton Pattern Let’s have a chat about the Singleton Pattern. One of the most known and (mis?)used patterns out there. The Singleton Pattern is relatively straightforward and easy to implement. It is both its strength and where the problems appear. We will also show a couple of examples or where you can find the …

Read Article Read More

pattern Builder Pattern – Creational

Builder Pattern – Creational

In this post, I’d like to talk about the Builder Pattern. This pattern is part of the Creational grouping in which other patterns such as Factory and Singleton are also a part of. For what do we use the Builder Pattern? Sometimes we might need to have objects that work in the same way, however, have …

Read Article Read More

pattern Creational Patterns – A short word about it

Creational Patterns – A short word about it

As mentioned in this previous post it is important that developers have an understanding of some patterns that are common in our profession. The Creational Patterns are a grouping of some of these patterns. A short word on Patterns grouping A “basket” of patterns, such as the Creational one, is used to put similar patterns together. This …

Read Article Read More

base-knowledge Thread: The makers of Programs

Thread: The makers of Programs

On a previous post, we talked about Processes. In this post, we will talk about ‘their offspring’, the Thread! What are threads? Threads are squiggly lines: But to be more realistic we can interpret the name Threads coming from: an analogy to the Thread of fabrics: they work together to span a piece of a …

Read Article Read More

practical The Coder’s MUST know

The Coder’s MUST know

Where is the idea coming from Uncle Bob once wrote on his “The Clean Coder” that there are a couple of concepts every programmer should know. You and I could add or remove a couple of items from this list, however I believe it is a good place to start from. So I would like …

Read Article Read More

musings Support or Why I won’t be migrating to Java 9 or 10

Support or Why I won’t be migrating to Java 9 or 10

Support. This is the reason I won’t migrate so fast out of Java8 completely. This is a short one! I recently wrote about Java9 and Java10, but I also wanted to share my opinion about the (now not so) new 6 month release cycle of Java. LTS The term Long Term Support first dropped into my …

Read Article Read More