Golang : Pass by Value Vs Pass by Refere

By default every thing in go is pass by value, which means if you pass any argument to a function, it would copy the values passed in another variable and make changes to it in function scope only (with in function block) and does not modify the original value.

Which means whatever you pass to a function in Golang remains immutable and does not get modified. However, if you use pointer then changes would impact the original value.

Try to read below program and understand it:

package main

import "fmt"

type Person struct {
       firstName string
       lastName  string

func changeName(p Person) {
       p.firstName = "Bad"
       fmt.Print("inside method with local scope on copy")

func changeNameWithPointer(p *Person) {
       p.firstName = "Bad"
       fmt.Print("inside method with local scope on pointer")

func main() {
       person := Person{
              firstName: "Good",
              lastName:  "person",
       fmt.Println("Original value of person", person)
       fmt.Print("Outside method with original variable passed as copy")

       fmt.Println("\n\n========Pass by pointer will modify values =======")

       fmt.Println("Outside method with original variable", person)
       fmt.Println("Outside method with original variable passed as reference (which is now changed )")


Sample output :

➜ passByValue git:(master) ✗ go run ValueVsReference.go
Original value of person {Good person}
inside method with local scope on copy{Bad person}
Outside method with original variable passed as copy{Good person}
========Pass by pointer will modify values =======
Outside method with original variable {Good person}
inside method with local scope on pointer&{Bad person}
Outside method with original variable passed as reference (which is now changed )
{Bad person}




Java Tutorial : Hands on project for library management application

I am coding Library Management Project in Java and teaching it in simple steps.
If you are interested in doing or learning Java with hands on project then check out this play list from my youtube video 🙂

Git Repo :

Project requirements:
For details visit : http://www.premaseem.com

MongoDB : Normalize Database reference (DBRefs)

The joy of a Document database is that it eliminates lots of Joins. Your first instinct should be to place as much in a single document as you can. Because MongoDB documents have structure, and because you can efficiently query within that structure there is no immediate need to normalize data like you would in SQL. In particular any data that is not useful apart from its parent document should be part of the same document.

This is not so much a “storage space” issue as it is a “data consistency” issue. If many records will refer to the same data it is more efficient and less error prone to update a single record and keep references to it in other places.

DBRef documents resemble the following document:

{ "$ref" : <value>, "$id" : <value>, "$db" : <value> }

Consider a document from a collection that stored a DBRef in a creator field:

  "_id" : ObjectId("5126bbf64aed4daf9e2ab771"),
  // .. application fields
  "creator" : {
                  "$ref" : "creators",
                  "$id" : ObjectId("5126bc054aed4daf9e2ab772"),
                  "$db" : "users"

The DBRef in this example points to a document in the creators collection of the users database that has ObjectId("5126bc054aed4daf9e2ab772") in its _id field.

Consider the following operation to insert two documents, using the _id field of the first document as a reference in the second document:

original_id = ObjectId()

    "_id": original_id,
    "name": "Broadway Center",
    "url": "bc.example.net"

    "name": "Erin",
    "places_id": original_id,
    "url":  "bc.example.net/Erin"

Then, when a query returns the document from the people collection you can, if needed, make a second query for the document referenced by the places_id field in the places collection.

Reference link for details : https://docs.mongodb.com/manual/reference/database-references/

MongoDb Tutorial by Premaseem (Free video course on MongoDB)

Hi Friends,

I am certified MongoDb expert. I though to share my knowledge with all, so that this entire world might get benefitted by it. It’s a free youtube video series with short lecture  covering different topics (31 topics).

Free video tutorial link :  https://www.youtube.com/playlist?list=PL13Vva6TJcSsAFUsZwYpJOfR-ENWypLAe

mongoDB tutorial on youtube.png

Use this free tutorial and share it with friends 🙂

Free online web based Terminals and IDEs on cloud

Whenever we want to learn some thing, there is a fight to setup machine, environment etc before we can begin, thanks to new cloud technology now you can start instantly using free online web based Terminals and IDEs on cloud





Free Online Linux Terminal to practice commands


If you want to try out linux commands without bothering to to through installation then try the free online linux terminal to practice commands.

This is simple



This has some additional features :