Category Archives: Reactive Programming

Reactive Programming in Swift

Reactive Programming in Swift

reactive-programming-in-swift

 

If you are an iOS Developer then you should have heard about RxSwift. It’s a swift version of Reactive programming. RxSwift is so powerful and effective that it will do all the work for you in code and make your life easy as a developer.

Don’t Believe? Then you might check this introduction of Reactive Programming to agree with me 🙂

Reactive Programming – Future of Programming

 

RxSwift is roaming around the following terms:

 

  • Observables & Observers
  • Subject
  • Operators
  • Schedulers

let’s start exploring all these stuff one by one.

 

 

  • Observables & Observers:

 

Rx swift

 

“ Event-A is emitting some data and other events (for example Event-B & Event-C) who subscribes to Event-A will get that emitted data. The event that emits the data (Event-A in this case) is called “Observable” or “Observable sequences” and all events (Event-B & Event-C in this case) that receives emitted data are called “Observers” .”

This is the most simple definition to understand Observable.

Observable data can be continuous or emit in more than one instance. Observers can receive all these instances one by one in sequence.

Let’s check the below diagram:

observable data

 

Here is how the coding representation in swift for the above diagram:

swift programming

 

  • The lifecycle of Observable:

 

Observables consist of three main events:

-Next

-Error

-Completed

two points to remember here:

(1) When observable emits the one element of data which is known as the Next event. In the above case, Observable A is emitting the data for six times. So observers will get that next event one by one.

(2) When observable will complete all the next event it will either terminate with completion or error.

lifecycle of observable

 

Let’s check some examples:

Array Example

 

If you are developing some serious apps than you should really care about memory leaks. So for that Observable has one important aspect which is known as “Dispose Bags”.

Once observable are done with all the next events and terminated at the end, we need to release all the used resources to avoid memory leaks. For that, we need to dispose of subscription.

dispose bags

 

If you want to get more idea about how can you use this concept to make your code better, Here is some more conceptual things you can try:

1_bDBEIEel2X1oIiBr4jb-4A

Conclusion:

To know the basics of reactive programming you can visit blog Reactive Programming – Future of Programming. Also if you want to hire a Reactive Programmer you can hire a developer from RemotePanda.

 

Reactive Programming -Future of Programming

Reactive Programming -Future of Programming

reactive-programming-future-of-programming

 

Developing great apps nowadays require many things like handle User Interaction, handle network related stuff, manage data as well as present them. For that Developer has to write lots of concurrent as well as asynchronous code.

Nowadays if you take a look on the internet as a developer than somewhere you have read the term Reactive programming. You might wonder what’s this term actually means and why it takes storm between the developers. Many developers say it is the Next big thing in the programming world. Maybe as a developer you are still unaware what the world is talking about so you are curious to know on this and make yourself to be the part of this incredible world of programming.

So if you are bibelot about this topic and search on the internet than here is what type of definition you will find:

“Reactive programming is an asynchronous programming paradigm concerned with data streams and the propagation of change.”

 

wikipedia

 

At the initial stage, it is very hard to understand what it really meant. This is the reason why I am writing this blog. So that everyone can able to know how reactive programming will help you in coding with an easy and understandable way.

I will try to explain to you in a very easy and fun manner that how it will attract you to use in your real-world apps and projects. I am sure you will definitely understand this by the fun conversation between me and my friend Taral

reactive programming example
reactive programming

 

As an application developer, we always need to make our app smooth as butter. For that we have to handle many things like below :

  • Handle multiple URL responses at the same time
  • Multiple UI changes
  • Manage Database
  • Handling all the other frameworks we are using
  • Many more things

 

To tackle all these we often use many frameworks also use some logic by putting UI related changes to the Main thread and other time-consuming stuff in a background thread. We’ll try to keep our main thread free. Writing code that truly runs in parallel, however, is rather complex, especially when different bits of code need to work with the same pieces of data. It’s hard to argue about which piece of code updates the data first, or which code read the latest value.

 

So for an alternative of all these, here comes the Reactive Programming to give you power and fight for your code.

 

Reactive Programming ~= Asynchronous programming

 

 

Basically, Rx is asynchronous programming that handles your code to react to the data in observable sequences. It defines the structural programming in which one component emits the data and other components which are registered to receive will propagate those changes.

There are three building blocks of Rx

1) Observables — Component that Emits the Data

2) Observers — Components that subscribes to observable to get changes

3) Schedulers — schedule the different pieces of data coming from observable

For example :

X = Y + Z

X is an observer here because it subscribes to the result of y+z

Y & Z are observables here because it omits the changes.

Rx

 

Conclusion:

 

This Blog Explains you Reactive Programming in the most simple way. If you want to know more about Reactive Programming you can visit our blog Reactive Programming in SWIFT

 

About RemotePanda

RemotePanda is a personalized platform for companies to hire remote talent and get the quality work delivered from the city Pune. The resources in our talent pool are our close network connections. While connecting them with you, we make sure to manage the quality, growth, legalities, and the delivery of their work. The idea is to make remote work successful for you. Get in touch with us to learn why RemotePanda is the best fit solution for your business requirements.

React Native : Worth the hype?

React Native : Worth the hype?

react native worth the hype

It has been a while that React has been around, but it was just last year that Facebook announced that it has built a library to build native apps using React ( read as Javascript ). Facebook decided to call this React Native.

There have been attempts at developing Javascript frameworks to build mobile apps, but I see React Native as a paradigm shift in the field. It is far far ahead as compared to other Javascript frameworks for building mobile apps in terms of performance. Having said that, the idea behind React Native was not building ‘write-once, run anywhere’ app but, more of ‘learn-once, write anywhere’ thing. For the sake of this article, let’s not categorize React Native with existing Hybrid Frameworks.

Having some free time lately, I found myself browsing the React Native docs and found it amazing. I would have been hugely disappointed in myself if I did not try this out.

 

Choosing the project:

Choosing-the-project

I did not have to think a lot about the kind of project to do in React Native. I did not want to write a server code for the app because the whole objective of the project was to learn React native and it would be an unnecessary burden on me writing a server. So options were clear —

1. Write a client-only app. e.g. An alarm clock or the classic To-do app. I could not come up with something interesting in the category.

2. Consume an API service and write a client. A Reddit client! Yes! That way I can use my app for browsing Reddit and make incremental improvements to the app as well.

(Reddit API is quite straightforward and easy to grasp. Let us not go into its details as it would dilute the purpose of the article)

 

Setting Up:

Setting up React Native was quite easy. You get the required libraries from rpm, and that is it. Use your favorite editor/IDE and you are good to go. Personally, I would recommend using Atom by GitHub and installing the Nuclide package but people use vim or emacs with appropriate packages as well.

 

Learning Curve:

I would say if you have strong component-based programming experience, the learning curve would be much smoother. Otherwise, it might take you a while to grasp a few concepts but it should not be a tough nut to crack.

 

Experience:

 

 

what kind of sorcery is this?

 

Oh, la la! Writing JavaScript code and seeing it run on iOS emulator run as Native is impressive. What wizardry these guys have pulled off leaves you mesmerized.

Anyway, as my app began to grow I ran into a problem ( as is the case with developers ). In React, the state is essentially the core of the application, which determines how each component behaves and renders. In my case, the state of the application was being changed from a lot of places and soon it was difficult to track from which modules of my app the state was being changed.

 

Meet Redux:

 

Essentially a simplified Flow. It provides a framework to manage your state changes. It works on the principle of Action acting upon Current State, provides the Next State. React Native works coherently with the Redux Framework and solves much of your state change issues.

 

Overall Impression:

Overall-Impression

 

To me, React Native does look like a strong contender for the future of mobile app development. What remains to be seen is how this affects the current mobile app dev platforms.

Google looks comfortable with its Java-based Android SDK, although there was a rumor about Google switching from Java to Swift after it’s a lawsuit with Oracle ( which I find it unlikely in near future ). If that does happen, ‘learn once, write anywhere’ methodology is satisfied sans React Native with the perspective of mobile apps.

 

Conclusion:

 

Apple pushing its Swift language and rolling out updates, the stage looks set. What stands the test of time, remains to be seen. 

 

About RemotePanda

RemotePanda is a personalized platform for companies to hire remote talent and get the quality work delivered from the city Pune. The resources in our talent pool are our close network connections. While connecting them with you, we make sure to manage the quality, growth, legalities, and the delivery of their work. The idea is to make remote work successful for you. Get in touch with us to learn why RemotePanda is the best fit solution for your business requirements.