Deep copy and Shallow Copy

This is an important concept of computer science. You may have heard it very less in your day-to-day work life but your work will directly or indirectly relate to this one of the main concept of memory management. Let’s dive into this.

Here is scenario – Assume you have a team of 5 members. You have created a document on Google Drive and shared the link to the document with your team members.

Now how the doc is used / consumed is upto the members. Primarily there are two ways:

  1. One is : Using the online version directly to read/update or if someone updates you get the latest update directly. One can see the changes live.
  2. The other way is: Download a copy to your local system and use it as per your wish, manipulate it update it without altering the original copy which is on the cloud.

Thats it. If you know the difference between the 2 above,You got the concept! The first one is Shallow copy of the document and the second one is Deep copy of the document.

Now using this analogy let me explain you the memory management concepts of Objective-C and Swift.

  • strong : Members who have doc added to their own drive. Even if original is deleted the doc is not deleted. The reference link still points to the doc
  • weak : Members who have access to the doc will be informed upon deletion of the doc. Now the reference link will be invalid. It will point to nil.
  • assign : Members who have access to the doc will NOT be informed upon deletion of the doc. Now the reference link will be invalid. App crashes if the link is accessed.
  • copy : Members download copy of the doc to their own system. Does not effect if either of them are modified or deleted. Takes up additional memory unlike the above 3 which are referenced to same memory location. Mutable copy is when document is downloaded with RW permissions.

The 4 statements above may or maynot hold good for Google drive but only used to explain the concept.

Pros & Cons:

Shallow copy

  • Doc link which is stored in the cloud
  • Owner and admins is the strong reference
  • Non admins will have weak reference
  • Changes to the document will be notified to every member

Deep copy

  • Document downloaded to local system
  • Consumes additional storage
  • If some one changes in the cloud does not effect your local system
  • Whatever you change locally does not effect cloud version

I made up this analogy because I found it easier to link both the concepts for understanding. Let me know if you find this difficult or missing. Please share your comments below.


Dam's DEV Profile


AWS in 5 minutes

This post will give you a basic understanding of what Amazon Web Service is, how components in it works, what each component is responsible for at a very high level – all these in just 5 minutes.

This post is gives you a brief idea about the components used in aws. This will surely help you understand things when aws developers are discussing about topics and issues while at work.

EC2Elastic Cloud Computing instance is where you run your web app server or a micro-service server. This is one of the primary component of AWS. You can create multiple instances of the servers in multiple availability zone so that if one zone goes down your services to end users are not affected. Session maintainence can be configured here or in ELB

ELBElastic load balanacer automatically distributes incoming application traffic across multiple targets. It handles the traffic coming from the public networks (users/mobile/consumers). The major functionality of this component is route the traffic to different servers balancing the load from incoming traffic. It can handle the varying load of your application traffic in a single Availability Zone or across multiple Availability Zones.

ELB facing the public network will be inside a public subnet to make it accessible. Apart from this and S3 instance all other components will be inaccessible to public as they will be configured with private subnet. This would be the best place to have session stickiness.

S3Simple Storage Service is used for storing all static files like documents, audio, video, image files. This service is only used for storing and retrieving the files. Glacier is used in connection to S3 to archive the least used or unused files to reduce the storage space.

The diagram represents typical web app architecture using some of the important components of amazon web services. Also shows the interactions between the components.


RDSRelational DataBase is the place where you store and manage your application data. This service supports RDBMS solutions like MySQL, etc. This service also supports the Master-Slave architectures.

NoSQL DB are used if web app solution needs a document based databases like DynamoDB, etc.

Security Group – is used to manage the access to service anyone can have. Each service must ideally have a security group defined.

Route 53 is a highly available and scalable cloud Domain Name System (DNS) web service. It is designed to give developers and businesses a way to route end users to your application servers.

IAMIdentity and Access Management is the one where you can add/update/delete users and their permissions. Generally there will be end users, administrators, developers.

Elastic Cache is a managed, in-memory data store services. You can choose Redis or Memcached to power real-time applications. ElastiCache is a popular choice for Gaming, Ad-Tech, Financial Services, Healthcare, and IoT apps.

For administrators: CloudWatch monitoring service for AWS cloud resources and the applications you run on AWS. It keeps an eye your whole setup and triggers a notification using SNS service to email the administrators if there arises any warning or alert on servers using SES service.

Lambda services are generally used for solutions designed with serverless architectures.

Hope this would be useful to in one or the other way, at least giving you a sneak peak about what AWS is all about.

Obj-C — Swift — Obj-C

This is one of the rare scenarios one might get into, but the problem and its solution are unique and the simplest one here.

  • Have you come across a scenario where you felt the need for an additional method in a class inside a framework (one of the Pods you added) to achieve your work?
  • Is the library implemented in Objective-C?
  • Is your legacy code in Objective-C and now you are strategically moving to Swift?

Today at work my friend, Vinodh, asked me this:

“I have a pod framework which is in Objective-C, I need to add a functionality but needs to be used in Obj-C for now and may be used in Swift file in future. What is the best way to do this?

Let us say we have a class called Person inside one of your pod frameworks. This Person class has name, age and gender as properties, with a function to format the name.

// Objective-C header file of Person class

typedef enum : NSUInteger {
} Gender;

@interface Person : NSObject

@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) Gender *gender;
@property (nonatomic, strong) NSUInteger *age;

- (NSString*)formattedName;


// Objective-C Implementation of Person class
@implementation Person

- (NSString*)formattedName
    return [NSString stringWithFormat:"This is %@",];


When the formattedTitle method is called on a person object with value for name property ‘Vinodh’ it would print like “This is Vinodh”.

Now we need to extend this Person class with another method say a new format which tells the age along with the name.

In classic Objective-C style it would be adding a category to Person class, Importing this category wherever you need this new method. This would have been the best way before Swift was introduced.

But there is a disadvantage if new developer join unitl and unless (s)he imports the category header, code completion will not show the new method. Probably the new developer will end up writing the same method creating a new category again. This is a problem.

Swift to rescue. Do the following:

  • Create a Person class extension and write the needed method
  • Now create a protocol and declare the method signature
  • Now prefix the protocol with @objc to make this available in Obj-C files

Here’s how you do it.

@objc protocol Formats {
    func getFormattedName(with ageHidden: Boolean) -> String

extension Person: Formats {
    func formattedName(with ageHidden: Boolean) -> String {
        let formattedString: String = ageHidden ? "This is \(" : "This is \( aged \(self.age) years."
        return formattedString

Now wherever you type [personObject form… in Obj-C or in personObject.form… in Swift the code complete will show you both the methods one Person class another from the extension we added.

Love to hear more stories from your side. Please do share in comments.

Happy Coding!

WordPress on local machine

When I talked to a friend about learning wordpress development he said why do you want to learn wordpress now? Its an old technology. Now everyone is moving to either Medium or having their own blog developed from scratch.

It’s a true, a reality. With node, MEAN stack, Swift for server side and similar other frameworks a developer can build and run his own site with latest technology. WordPress still works on php, MySQL – the classic xAMP stack.

Why do you want to learn wordpress now? Its an old technology. Now everyone is moving to either Medium or having their own blog developed from scratch.

This doesnt mean we should stop learning old technology which are still doing good. Those are the systems which are still doing good, scaling good. They are thought through and are designed in a better way to last long compared to any new platforms today. I mean Facebook is still powered by php.

This doesn’t mean new technology is not there in terms of scalability. Sad truth is most never get opportunity to scale. Some never see the light of the day and some which get to see hardly have any subscribers and developers of that blog never scale them.

Why am I learning this now?

Learn and understand, experiment, know inside of it and whereabouts of what needs to be done then customize it according to your needs.

  • WP gives a base to start creating your own websites primarily blogs.
  • Lot of templates available or build your own and share.
  • Spend time in customizing as per your needs rather than build from scratch.
  • We can learn how various components are used.
  • Architectures and patterns followed.
  • The schema design.
  • Its always interesting to learn old technologies.

This is the reason why I went ahead with starting on wordpress. As a first step I wanted to install wordpress and try some themes and plugins. But to install I need a server to host and need a database hosting too. Next I searched for how to install WordPress locally on my system? got the results.

It needs a xAMP stack – Apache-MySQL-PHP either on Linux, macOS or Windows. I have a macOS. Now next come how to start a Apache server? After some searching on internet Found MAMP which makes your task very easy. MAMP is for macOS and Windows too and there is another one WAMP for windows only.

There is no better way to have a server of your own for free and do your experiments. And the only best way for this full freedom installing it locally on your system.

Install WordPress locally:

  • Download MAMP
  • Install MAMP or WAMP as per their site
  • Download WordPress Remember this is not .com
  • Unzip the downloaded wordpress file, you must get a folder – wordpress
  • Copy the wordpress folder into installed MAMP folder’s htdocs folder*
  • Now click on Start servers
  • Once the loading spinners stop and you see green in front of Apache and MySQL your servers are running
  • Open your favorite browser and type http://localhost:8888 and hit enter
  • Set up database –
    • Go to localhost/phpmyadmin
    • Go to Databases, add a name for the table and click Create
  • Configure WordPress –
    • Now open a browser tab and type localhost:8888/wp-admin
    • Follow the wizard
    • When asked for enter Database name, username, password, Host
    • By default username and password both are ‘root
    • Leave the Table prefix as it is and click Submit
    • Next click on Run Installation
    • Give a name, username-password and email-id for your blog
    • Click on Install wordpress. Success!
    • Now when you login, you should be able to see Admin console
Congrats!! You are up and running 
wordpress instance locally

*Alternatively you can also set the path from which MAMP has to serve. Launch MAMP – Go to Preferences – Web Server tab – Change the Document Root folder.

Where to go from here?

I am yet to do this, but definitely next step is to design your website and customize your wordpress installation. Here is a 7 video series on how to build a wordpress site

Now explore installing themes, creating a couple of themes and plugins. Along with creating them it will be interesting to understand how everything fits. I have just installed WP on my system and yet to explore all these.

This is where I learnt how to install WordPress locally.

Swift meetup

After a long time attended a meetup. And this was on the topic which I work on day to day – Swift programming language.

The meetup overall was good. Got to learn couple of new things – DispatchGroups, Swift Runtime and the thing that we can have our own Swift’s virtual environment just like virtualenv in Python, for swift its called virtualswift.

The most useful talk for me was on measuring performance in swift by Mayur Dhaka in which I can use immediately is DispatchGroups.

DispatchGroup primarily avoids the code shifting to right while using nested blocks like completion handlers.

From what I understood is DispatchGroups are the thing which can be used to group a logical set of background operations into one unit. It has very few APIs. According to Apple :

DispatchGroup().enter() – to indicate the block has entered the group.

DispatchGroup().leave() – to indicate the block in the group has completed.

DispatchGroup().notify(...) – to schedule a block or a work item to be submitted to a queue when a group of previously submitted block objects have completed.

DispatchGroup().wait(...) – waits synchronously for the previously submitted work to complete.

Basically DispatchGroup is to synchronize and track a set of tasks which are logically grouped and executed according to your requirements.

Hope this gist will help you get to know something new and explore more if interested.


The 5 minute series

As mentioned in my previous blogpost the first among my targets this year is to start a 5 minute series to get introduced to anything. With this post I am listing down my initial set of topics which I will be writing on. This list will grow periodically and also will be updated with the links to each 5 minute series.

Following are the topics for which I am planning to do 5 minute introductions this year

I will be adding more to this list I finish each one.

This is the first time I am doing a 5 minute series. So your comments and suggestions are very very important to me. All criticism is taken up for improvement of such tutorials.

iOS Keyboard Shortcuts

Do you want to save time typing the same phrases again and again? Yes!

Especially on your phones where you have a cluttered keyboard and for the ones who are used to desktops typing on phones can be really really cumbersome.

Here’s a saver for you. There are many apps which can create shortcuts for you. But the one which comes by default in iOS: ‘Text Replacement‘.

Where to find this and how do I set the shortcuts:

  1. Go to Settings app
  2. General → Keyboard → Text Replacement
  3. Go to top right corner and tap on the + icon to create new shortcuts.
  4. Add the phrase and shortcut text you can remember
  5. Use this in anywhere in the device wherever you can type

I use this while replying on linkedin with “Thanks for the opportunity. I am not looking for a change…” I use “lnkdthnks” as shortcut. A real time saver!!

Another place I use this is when my friend, Gourav, asks me to keep reminding him about creating videos etc., For the text “Gourav when is the video coming out?” I have added the shortcut ‘galert‘. Timesaver, right?

Hope this helped!

Keep following for more tricks and tips on All things tech!