Best resources to learn Go programming language!!

Golang aka go programming language is the fastest-growing programming most loved programming language.

If you think you are not used ” go ” directly or indirectly then I think you are wrong. Have you heard about Docker containerization technology then you are indirectly using Go language in your day to day basis.

Docker is written in the Google Go programming language.

What is GoLang?

Go-Lang is an open-source language officially released by the Google production team in 2009. It was developed by Robert Griesemer, Ken Thompson and Rob Pike. It is a multi-purpose programming language specially designed to build faster and scalable applications. It provides features like fast compilation, garbage collection, dynamic types, concurrency, standard libraries, and packages.

Let us take a tour to understand what are the best resources available to get started this programming language.

1. Go Tour:-  

This is my favorite site to get started and make our hands dirty. This is the official Go Tour website: https://tour.golang.org. The best things about this site are that the tour is available offline just by running go tool tour in your command line if you have already installed Go-lang locally. This is providing an interactive tutorial where you can run your code snippet and it gives you an overview of Go-Lang. The tour is classified into different sets of modules.

2. Go By Example:- 

Another effective to start go-lang learning is going by example. Go by Example is an interactive online course tutorial for learning Go. Once you know the basic then go ahead and hit the Go by example (https://gobyexample.com). Start hacking by taking examples and get moderate knowledge about go-lang. 

3. Effective Go:-

This is another official resource to learn go-lang. This is also available for free. This is a very interesting website https://golang.org/doc/effective_go.html to explore more about the go-lang. I found it very useful especially because is not just a syntax reference document but a more complete description of all the Go features and constructs and how to use them effectively. This is where you will get some level of expertise.

4.Golangbootcamp:-

Golang Bootcamp is a mini book to start learning go-lang. How to get started on Go? Hit this URL http://www.golangbootcamp.com/book/ to explore this book. This book will open a window for you to start learning effectively go-lang. The best thing about this mini-book is, it has a list of basic constructs and concepts and all those attached with go-lang playground. 

5. Go-Playground:- 

Now you know basic of go-lang language and you know how to construct the things. you no need to install go-lang locally on your system to start. We have online https://play.golang.org/ go-lang playground to test your knowledge and constructs. 

6. Go-Lang FAQ:-

Go-lang FAQ is really golden gate for you to understand the core concept and clarify your Bigbang doubts. This is also an official website https://golang.org/doc/faq.

7. Go-lang Bot:-

Golangbot is a fun and easy way to follow and learn Golang consistently and regularly. This can help you in improving your coding, solving practical issues, basics of Golang to advanced tutorials. This is inclusive of all learning materials of Golang. here you will get a different experience of learning. 

Hit this URL to go https://golangbot.com/ and start with hello world to a complex program and Quizs too.  

8. Tutorials Point:-

The tutorials point is also one of the best resources to get familiar with go-lang. if you are an avid reader and learner you should know tutorials point. 

https://www.tutorialspoint.com/go/.

9. Go-Lang Tutorials:-

GoLang tutorials is the best free online classes to learn go-lang. These classes best suited for professionals as well as beginners. It has a cover of the basic concept, control flow, looping, interfaces, memory management, etc. Tutorials are classifieds into sections and all sections having examples.Table of Contents
Audience Installing and configuring Go A step by step approach to Hello World in Go Updated for Go1 Typical early…golangtutorials.blogspot.com

10. Reference Books:-

  1. Introducing Go by O’Reilly.
  2. Go in Action.
  3. Learning Functional Programming in Go.

Conclusion:-

These are my findings. Please let us know your resources to learn go-lang. How you started and what are the other resources do you think are better to start learning go-lang.

Junit5 Assumptions

Assumptions are used to run tests only if certain conditions are met. This is typically used for external conditions that are required for the test to execute properly, but which are not directly related to whatever is being unit tested.

If the assumeTrue() condition is true, then run the test, else aborting the test.

If the assumeFalse() condition is false, then run the test, else aborting the test.

The assumingThat() is much more flexible, it allows part of the code to run as a conditional test.

When the assumption is false, a TestAbortedException is thrown and the test is aborting execution.

@Test
void trueAssumption() {
    assumeTrue(6 > 2);
    assertEquals(6 + 2, 8);
}

@Test
void falseAssumption() {
    assumeFalse(4 < 1);
    assertEquals(4 + 2, 6);
}

@Test
void assumptionThat() {
    String str = "a simple string";
    assumingThat(
        str.equals("a simple string"),
        () -> assertEquals(3 + 2, 1)
    );
}

https://www.techwasti.com/junit5-tutorial-part-1/
https://www.techwasti.com/junit5-part2/

Junit5 tutorial: Part2

Before exploring this part, please read first part 1 is here.

Junit5 for beginners. In this tutorial let us make our hands dirty and have practical experience. If you are using Maven or Gradle for either of the build tool you can use dependency.

Maven dependency for Junit 5.0:

Add below dependency in pom.xml.

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>

Junit 5.0 with Gradle:

Add below dependency in build.gradle file. We can start by supplying the unit test platform to the build tool. Now we have specified test platform as Junit.

test {useJUnitPlatform()}

Now after the above steps, we need to provide Junit5 dependencies here is the difference between Junit4 and junit5. As we have discussed in previous article Junit5 is modular so we have three different modules and each one has a different purpose.

dependencies 
{
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}

In JUnit 5, though, the API is separated from the runtime, meaning two dependencies have to provide testImplementation and timeRuntimeOnly respectively.

The API is manifest with junit-jupiter-api. The runtime is junit-jupiter-engine for JUnit 5, and junit-vintage-engine for JUnit 3 or 4.

1. JUnit Jupiter:

In the first article, we have explored the difference between Junit4 and Juni5. There are new annotations introduced as part of this module. JUnit 5 new annotations in comparison to JUnit 4 are:

@Tag — Mark tags to test method or test classes for filtering tests.

@ExtendWith —Register custom extensions.

@Nested — Used to create nested test classes.

@TestFactory — Mark or denotes a method is a test factory for dynamic tests.

@BeforeEach — The method annotated with this annotation will be run before each test method in the test class. (Similar to Junit4 @Before )

@AfterEach — The method annotated with this annotation will be executed after each test method. (Similar to Junit4 @After )

@BeforeAll — The method annotated with this annotation will be executed before all test methods in the current class. (Similar to Junit4 @BeforeClass )

@AfterAll — The method annotated with this annotation will be executed after all test methods in the current class. (Similar to Junit4 @AfterClass )

@Disable — This is used to disable a test class or method (Similar to Junit4 @Ignore)

@DisplayName — This annotation defines a custom display name for a test class or a test method.

2. JUnit Vintage:

As part of this module, there is no new annotation has introduced but the purpose of this module is to supports running JUnit 3 and JUnit 4 based tests on the JUnit 5 platform.

Let us deep dive and do some coding:

@DisplayName and @Disabled:

As you can capture from the below code snipept you can DisplayName I have just given two flavors of one method. This way you can provide your own custom display name to identify test easily.

@DisplayName("Happy Scenario")
@Test
void testSingleSuccessTest() 
{
System.out.println("Happy Scenario");
}

@Test
@DisplayName("Failure scenario")
void testFailScenario() {
System.out.println("Failure scenario")
}

To disable test cases which implementation not yet completed or some other reason to skip that

@Test
@Disabled("Under constructution")
void testSomething() {
}

@BeforeAll and @BeforeEach :

BeforeAll is like a setup method this will get invoked once before all test methods in this test class and BeforeEach get invoked before each test method in this class.

@BeforeAll annotation must be, static and it’s run once before any test method is run.

@BeforeAll
static void setup() {
System.out.println("@BeforeAll: get executes once before all test methods in this class");
System.out.println("This is like setup for tests methods");
}

@BeforeEach
void init() {
System.out.println("@BeforeEach: get executes before each test method in this class");
System.out.println("initialisation before each test method");
}

@AfterEach and @AfterAll:

AfterEach gets invoked after each test method in this class and AfterAll get invoked after all test cases get invoked. Afterall like finalization task.

@AfterAll annotation must be, static and it’s run once after all test methods have been run.

@AfterEach
void tearDown() {
System.out.println("@AfterEach: get executed after each test method.");
}
@AfterAllstatic void finish() {
System.out.println("@AfterAll: get executed after all test methods.");
}

Assertions and Assumptions:

Assertions and assumptions are the base of unit testing. Junit5 taking full advantage of Java8 features such as lambda to make assertions simple and effective.

Assertions:

Junit5 assertions are part of a org.junit.jupiter.api.Assertions API and improvision have significantly as Java 8 is the base of Junit5 you can leverage all the features of Java8 primarily lambada expression. Assertions help in validating the expected output with the actual output of a test case.

@Test
void testLambdaExpression() {
assertTrue(Stream.of(4, 5, 9)
.stream()
.mapToInt(i -> i)
.sum() > 18, () -> "Sum should be greater than 18");
}

As you are aware of using lambda expression because of lambda expression

All JUnit Jupiter assertions are static methods

@Test
void testCase()
{
//Pass
Assertions.assertNotEquals(3, Calculator.add(2, 2));

//Fail
Assertions.assertNotEquals(4, Calculator.add(2, 2), "Calculator.add(2, 2) test failed");

//Fail
Supplier<String> messageSupplier = ()-> "Calculator.add(2, 2) test failed";
Assertions.assertNotEquals(4, Calculator.add(2, 2), messageSupplier);
}

With assertAll()which will report any failed assertions within the group with a MultipleFailuresError

Pragmatic REST API design guide.

Best way to design REST API.

I have both experiences as API developer and API consumer too. I am curious to know is there any best practices, There should be some consensus, here is the answer Google released an API design guide recently.

Characters of design good API:-

  1. Easy to learn
  2. Easy to a consumer without documentation.
  3. Secure & scalable.
  4. API should be easy to extend.
  5. Deliver higher quality in lower cost.
  6. Appropriate to an audience.
  7. High adaptability & Productivity.

The Google API design guide is pretty straightforward in its purpose, with a goal of helping “developers design simple, consistent, and easy-to-use networked APIs” — but I thought it was noteworthy that they were also looking to help “converging designs of socket-based RPC APIs with HTTP-based REST APIs.”

“This Design Guide explains how to apply REST principles to API designs independent of programming language, operating system, or network protocol. It is NOT a guide solely to creating REST APIs.”

Most of the companies think that API design is only in the context of REST API design this guide will help you to think beyond the REST API design style.

The best thing about this guide is this is not only for REST. I think many of the developers already aware of the API style book. API style book is really best guide to designing REST API. If you don’t know about the API style book then go through it and apply the same in your tool suite.

I love the way google guideline explain to us How to design good API.

API should do one thing and do it well.

Don’t leak implementation logic. Names really matter in API design, names should be largely self-explanatory. API should like prose.

This is the simple my understanding about the Google API design guideline and let me know more from you, How you guys design API in an organization?

If you enjoyed this article, please don’t forget to Clap.

For more stories.

Let’s connect on Stackoverflow, LinkedIn, Facebook& Twitter.

Interactive Java (REPL) shell.

Interactive Java (REPL) shell.

For more stories.

When I started learning about the python I encounter with the interactive shell, which is a really cool feature to explore the API, prototyping then I feel why it is not in Java. But the answer is here. JDK 9 come with project kulla. What is the goal of project kulla? Master in Java9

The goal of the Kulla project is to investigate the creation of a
Read Evaluate Print Loop (REPL) tool for the Java programming
language.

When my friend ask me why you love Java. I told them Java is rich. There is a native way to REPL (Read-eval-print loops). If you want to checkout quickly the System.out.print(“Hello world”); then you have to create a separate project. JShell has emerged a powerful tool introduced in JDK9.

JShell is playground, on playground you can play cricket, football or whatever you want.

JShell is deeply integrated with JDK. JShell is tightly integrated with the Java compiler and Java virtual machine, JShell enhances the programming experience for the Java language. You can test your code as you create it, and way before you are done with your whole project. JShell is simple UNIX shell it will read instruction set, evaluate them & present the outcome.

JShell’s Advantages.

  1. It reduces the Java learning curve
  2. Start expression rather with classes.
  3. Immediate feedback & easy understanding.
  4. Explore new API, experiment, instantly get a result.
  5. Incrementally write complex code.

JShell takes two kinds of inputs

  1. Java code “Snippets” — snippet is small chunks of code.
  2. JShell Commands.

Experience without theory is blind, but theory without experience is mere intellectual play.

Let’s experience the JShell & interact with the project kulla. Get your hands dirty.

For downloading the JDK9 click here.

For mac os multiple JDK path. Please go through this.

  1. Download latest JDK build
  2. set the Java_Home path & check java version

3) Open terminal/ command prompt type jshell.

If Jshell not open then I have a trick for mac os redirect to the below path

/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/bin/

The world is your playground. Why aren’t you playing? Let us play.

Let’s play and enjoy. If you are the wrong jshell will give you the meaningful message. Please look below message ” it created variable all, it cannot be referenced until class lists are declared”.

You can declare, define & call a method from jshell.

JShell Commands

List of JShell commands

/help — to get the list of commands.

| /list [<name or id>|-all|-start] — list the source you have typed

| /edit <name or id> — edit a source entry referenced by name or id

| /drop <name or id> — delete a source entry referenced by name or id
| /save [-all|-history|-start] <file> — Save snippet source to a file.
| /open <file> — open a file as source input
| /vars [<name or id>|-all|-start] — list the declared variables and their values
| /methods [<name or id>|-all|-start] — list the declared methods and their signatures
| /types [<name or id>|-all|-start] — list the declared types
| /imports — list the imported items
| /exit — exit jshell
| /reset — reset jshell
| /reload [-restore] [-quiet] — reset and replay relevant history — current or previous (-restore)
| /classpath <path> — add a path to the classpath
| /history — history of what you have typed
| /help [<command>|<subject>] — get information about jshell
| /set editor|start|feedback|mode|prompt|truncation|format … — set jshell configuration information
| /retain editor|start|feedback|mode — retain jshell configuration information for subsequent sessions
| /? [<command>|<subject>] — get information about jshell
| /! — re-run last snippet
| /<id> — re-run snippet by id
| /-<n> — re-run n-th previous snippet

| intro — an introduction to the jshell tool
| shortcuts — a description of shortcuts

For example ‘/help intro’.

Then play and enjoy. Thanks for reading.

If you found this post is helpful, recommend it to others.

For more stories.

If you enjoyed this article, please don’t forget to Clap.

Software Architecture What, Why & How ???

Software Architecture What, Why & How ???

For more stories.

What is architecture ?

Architecture is arranging the blocks in modular, structured manner. Architecture is Art & architect is the artist.

Everything required architecture, it is not rocket science. Every one is the architect in a day to day life. In our house we are arranging our material, books, kitchen tools anything that we arrange in well manner is architecture. The shopkeeper arrange shop. Anything arranged in modular & structured manner is architecture.

Architecture is an art, so in art we have patterns & styles. The styles & patterns are changed based on the context, domain, and problem.

As per the Wikipedia which defines software architecture as “the set of structures needed to reason about the system, which comprise software elements, relations among them, and properties of both.”

Good software architecture is describe the applied patterns, layers or tiers which are used to define the clear separation of concerns of your business.

Why it is required ?

Less Is More. The WhatsApp Architecture Facebook Bought For $19 Billion.

As stated by Microsoft, “The goal of architecture is to identify the requirements that affect the structure of the application. Good architecture reduces the business risks associated with building a technical solution.

Architecture must be like switch, plug & play. Business is ivy it grows, just you need to manage. Good architecture is easy to understand & cheap to modify.

The success of business is depend on the architecture.

Benefits of architecture.

Benefits which we always curious about it. Without benefits there is no business.

Below are the benefits you will get if you fallow the architecture styles & patterns.

  1. High Productivity.
  2. Better maintainability.
  3. High adaptability.
  4. Makes It easier to reason about and manage change.
  5. Secure & Scalable.
  6. Deliver higher quality in lower cost.

Architecture defines set of rules and constraint that are specific to the system or project. Architecture enables the quality attribute of the system or we can say it defines the quality with every action.

How we design a good architecture ?

To become a expert we need to practice. Practice for perfection.

There are some important principles need to be consider while designing architecture.

  1. Common sense :- (What is it ?) is a basic ability to perceive, understand, and judge things.
  2. The system should be built to change instead of building to last.
  3. Learn from your past experience & current technology trends.
  4. There’s more way than one to do it. ( It is useful to find the optimise solution )
  5. Understand the end user context & business domain.
  6. Follow the Design patterns & styles.
  7. Follow coding best practices.
  8. Understand the business module, sub module, consider component & layers (tiers ) to abstract them & identify the key interfaces.
  9. Use iterative approach while designing architecture.

Software architecture & Software design are two different thing don’t mix them. Software architecture is skeleton while software design is meat.

Software architecture is more about the higher level & software design is more about there component, class or modules.

Software architecture patterns e.g MV* pattern & software design patterns e.g DAO, Factory.

Any software architecture has two key components.

  1. Architecture Patterns :- It defines the implementation strategies of the components.

2. Architecture Style :- It actually defines the components & connectors.

” Life is better when things are made for good. “

Software Architecture Category

  1. Communication
  2. Deployment
  3. Domain
  4. Structure

There is lot more to explore in software architecture. Would like to hear your suggestion, inputs on this post.

For more stories.

Lets connect on Stackoverflow , LinkedIn , Facebook& Twitter.