Skip to main content

Concept is more important than Programming language constructs

    Programming languages are evolving faster in the Information Age. The rapid growth in the language features and new Programming languages being introduced in the market is overwhelming. It is difficult to keep up with this pace. Moreover organisations like Oracle which adopted 6 months release cycle using Agile process has given us very little time to learn new things and establish our stronghold. When I went through few of these Programming languages I found the usual pattern that conceptually they are very similar only the Programming construct is different. Hence I believe the concept is more important than Programming language construct.

    Let's take an example of Groovy and Java 8. Both of these languages have the concept of lambda but the programming construct is different. In Groovy Programming language they call it Closure and in Java 8 they called it Lambda. The concept is same to pass code as an argument. The concept of code as an argument is to extract the reusable code or extracting change from the constant.

Groovy Closure vs Java 8 Lambda Constructs

     Above image shows how the way we could write the code is Groovy vs Java. In case of Groovy the curly braces are wrapping the entire code in case of Java parameters are outside the curly braces. Now we can argue that the differences are not limited to these but each Programming language will provide different options and restrictions. The implementation they follow may be different. But if we learn the very basic concept then we can write better code. We get engrossed in learning the programming constructs and then hardly find time to understand the concept. Hence start understanding the concept first then you can go to the language construct. When you are learning a new Programming language, even if you may not know the construct but the concept being similar all you need to do is learn the construct.

    How the closure or lambda is useful ? The official documentation emphasises on the anonymous inner class and the concise code. In true sense its beneficial is separating the change from the constant. Consider below scenario


   In this case we are looping through the list of contacts and based on the type of contact whether Email, Instant Message ID and Mobile Number we are sending appropriate Notifications to destination. Here notification type varies with Destination.  The constant in this case is to LOOP through some list and based on the the CONDITION ( Predicate ) we are performing certain ACTION which varies based on the condition. We have now created a generic code which will follow same pattern

LOOP -> CONDITION -> ACTION

    Noticeable feature here is that the generic code can invoke a code ( i.e Condition and Action ) which is passed as an Argument.

    With this thought process it does not matter if you know many Programming languages or not but learning any new Programming language will be easier for you.




References :


Comments

Popular posts from this blog

Container detached from docker network

Introduction One fine day you find out that one of your docker containers is running but is not currently attached to the container network that you created using docker network command. Ideally a container should be detached from the network when there is some error in it. However, if you set the restart: on-failure in the docker-compose.yml  in that case the container should restart and still be attached to the network. In such a weird situation follow the steps documented in this blog. Possible reasons Listed below are the possible reasons for this issue Storage space issue Memory issue ( We will cover this in next blog ) Storage space issue We need to check the space utilisation at the server level first then drill down to the docker engine. Server level utilisation In most cases the server is ubuntu system hence check the disk usage using the disk free command (i.e. df -h ). It will show you the current storage space utilisation of the server. df -h Docker engine space utilis...

Ruby on rails with Nexus

Introduction In this blog we will use nexus setup for NPM for a project which uses Ruby on rails. In this ruby on rails project we are using YARN and BUN  framework. We did setup a nexus NPM proxy and private repo but yarn could not fetch the npm dependencies via the nexus proxy. The rails assets precompile task however uses bun which uses npm. YARN is a wrapper on the NPM hence it does not entirely rely on NPM. BUN is a runtime which performs all the NPM tasks. Our goal in this blog is to understand how to handle this scenario in a ruby on rails project when use NEXUS NPM proxy. Technical specifications We have below versions of the tools NEXUS : 3.37.1-01 NPM : 9.5.0 NODE : v18.15.0 NVM : 0.39.1 ( Node version manager ) Mac OS : Sonoma 14.2 YARN : 3.5.1 BUN : 1.0.0 Steps Below are the steps required Configure NPM proxy in NEXUS Configure NPM private hosted repo Configure NPM group in NEXUS Change local NPM config for registry Change the YARN config for registry Configure BUN co...