Skip to main content

Posts

Kotlin Coroutines : A Comprehensive Introduction

Photo by Fleur Treurniet on Unsplash “Redesigning your application to run multithreaded on a multicore machine is a little like learning to swim by jumping into the deep end.” —Herb Sutter, chair of the ISO C++ standards committee, Microsoft® In this article What are coroutines? Blocking vs. Non-Blocking Kotlin Coroutines Suspending functions CoroutineScope Coroutine builders Coroutine dispatcher Coroutine start Conclusion What are coroutines? Coroutines have been around for quite a time now. They are in-fact one of the ideas which helped develop multitasking operating systems. A coroutine in trivial most is a subroutine or function generalisation which in non-preemptive environment (operating system or OS in short) can voluntarily yield the CPU time so that other such sub-routines can use it for themselves without losing the results of previous computations and then can conti
Recent posts

Kotlin: Higher order functions, Lambdas and Extension methods

Photo by Aaron Burden “Truth can only be found in one place: the code.” ―Robert C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship Happy winter, how are you?. This post is continuation of Kotlin series. If you haven't read my introductory post about Kotlin then I'll recommend you reading previous post before continuing with this one. Kotlin is a modern language. I've been working with kotlin for past few months now and I just love it. In todays post I'll talk about three features of kotlin viz. Higher Order Functions, Lambdas and Extension methods. This post also contains working code showing of each of these features. You are free to copy the code and experiment with it. If you haven't already setup kotlin on your system then you can run code using kotlin online playground . Higher order fu

Kotlin : An introduction

Photo by wu yi “A language that doesn't affect the way you think about programming is not worth knowing.” ―Alan J. Perlis World was nice and there was only assembly(“real programmers code in assembly”) but then one day out of blue he (hey! don't look at me like that I too don't know his name) came and said let there be compilers and interpreters(line by line) that will translate languages easy to read(uh! nah not really) and write into assembly to make programming fun again and that gave birth to an era of exotic new programming languages called procedural programming languages. Procedural programming languages were doing fine but after some time lot's of programmer started loosing their objects because of stateless functions which globally caused chaos. Seeing all this made him angry. So he said, “Procedural languages, I command you to treat everything as an ‘Object’ which will have it's own properties(attributes) and behavior(methods)”. They respond

Coding conventions part 2 : Aligning Things

“Programs must be written for people to read, and only incidentally for machines to execute.” —Harold Abelson Hello there, welcome to another post in the “Coding conventions” series. This post is solely based on question, “How to align code?”. If you are coming to this post directly then it is highly recommended that you read this post about naming different sections of code first. It contains both introductory talk about coding conventions and their importance and tips on naming things viz. methods, classes and variables. We humans are naturally in love with symmetry(tell me if I am wrong). Symmetry of faces, colors, things and their organization. A well-designed and aligned piece of writing makes reading both easy and fun. And when learning is fun remembering is easy. Undoubtedly things are no different in programming. A well aligned code is expressive and eye soothing. Correctly indented code blocks divided into equally sized chunks of statements really enhances quality

Coding conventions part 1 : Naming Things

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” —John Woods At some point in the life of every programmer comes a time, when he/she realize that the way he/she organize code sucks(I have this moment like every day). And it's time to change few things and start caring about the organization and readability of code. Code organization is crucial part of software development. Because software is not something which is developed from scratch again and again (as it will cost both time and money) but is updated and maintained for as long as it is possible to do so(this is why we have code re usability thingy). Programmer of special breed that is “Software Maintainer” is assigned this task. These are some of the most calm people in the industry because most of their salary is spent on Anger Management (May God bless them). If a code is poorly organized then more time is spent in refactoring it th

Where Girls Code.

Photo by Brooke Lark “Women are the largest untapped reservoir of talent in the world.” —Hillary Clinton So, It all started with a girl. She's a colleague, and she asked me a question which lead me to write this post. Let me first tell you a little about her and her question. Yesterday, while I was hanging out with one of my female friends(just friend people nothing more and by the way I am single ♥) and we were talking about programming culture and code (see this is why I am single). And suddenly she hustled and came in front of me and asked, “What do you think the main reason behind lesser number of female programmers than male programmers”. I said,“Simple, because, We men are much smarter than you guys”(I am sexist baby..... Uh! Okay jokes apart). And she hit me in stomach (man that girl hits very hard) and yelled,“I am serious Dav”. Anyway, soon she got distracted because there was a guy selling some girly pinky shoes(ew pinkish). But, her question, It started

Programmer's Editor Vs Normal Editor

“Nine people can’t make a baby in a month.” —Fred Brooks Have you ever used Notepad or some other text editor to write code? Then you might already have felt the pain of writing code in them. Although using text editor for coding will make you a better programmer in the long run but it'll cost you productivity. Programmer's Editors on the other hand are becoming mainstream because of two reasons; the features they provide, and they make code look fu*king awesome, I mean man, who doesn't like those colorful lines(Syntax Highlighting). And there are endless choices with each having some uniqueness in it while providing general features of programmer's editor which sadly makes it harder to select one. Problem with normal editor: No clear identification of various components of code. You have to write(or type) long sequences of code again and again. Code's alignment becomes head ache of programmer(more time is wasted in aligning code then actually writi