Monday, November 23, 2015

Java vs JavaScript

Yesterday wouldn't be the first time an aspiring programmer walked up to someone experienced and asked, "So what does JavaScript have to do with Java?"


The short answer is that it doesn't. They are not related at all, except by name.
However, they are both very popular and useful languages to their own merit, so we'll take an abstract look at them both.

Quick differences :

JavaJavaScript
  • Statically typed (variable datatype needs to be specified beforehand)
  • Dynamically typed (variable type is resolved directly during runtime)
  • Class based (functionality is stored in a way such that it belongs specifically to the instance from which it is accessed)
  • Prototype based (functionality is simply reduced to a property template that executes whenever required)
  • All non block statements should end with a semicolon.
  • Semicolon is optional in most circumstances.
  • Java has an implicit  this  scope, and an implicit class scope.
  • JavaScript has an implicit global scope, and during special events, an accompanying  this  scope.

If you're new to programming and the table above didn't make much sense to you, don't worry. The table just contains some technical details that'll help you to separate how one language works from another in your mind while actually writing code.
Since you're reading a blog post that's basically trying to pitch one language versus another, I'm going to assume that you might be more interested in the difference between these two languages in terms of application and use case.

Every environment has its own set of characteristic features that a programmer needs to keep in mind when developing in it, and I believe that the act of "putting yourself in the respective mindset" of that environment brings out efficient code in the end.
What I'm trying to say is that if you try to eat an orange like you would eat an apple, you might end up successful in your goal, but the overall experience will be messy and unsatisfactory. Hence, becoming thoroughly familiar with the frame of mind you need to be in for your environment first is important.

The Java mindset

A Java developer will have a concrete idea of the structure of every class in his project, like a map of properties and functions, so he knows how each instance will interact with each other. When you need to use a lot of object oriented logic, including inheriting from other classes, polymorphism, and modularization by separating functionality into their own classes, then you're going to be passing instances around a lot. That's how you know that you need a language like Java for your task.

Also useful to note is that Java has its own core set of libraries, and virtual machine platform where code is compiled.

Where to use Java :

  • For standalone apps - If you just want to create a command line or GUI application on the go, to run natively, Java is a good bet. In fact, you can't make Android apps without Java.
  • Browser Applets - Although Java applets are becoming rarer and old, sometimes they are used to extend the functionality of the limited power that web browsers have over your system.
  • Embedded devices - Java was originally written with portability in mind, such that it can easily be made to run in embedded projects due to its scalability.
  • Drivers - Java-like languages like C or C++ are often used to develop software to make hardware work, although you might want to use a language different from Java for this purpose.

The JavaScript mindset

A JavaScript developer will be aware of what's supposed to happen when. Picture a chain of events that fire off one after another. If you're developing in JavaScript, you should know the sequence of that chain and how to manipulate that sequence to get your desired result with only sufficient lines of code. You might have to juggle events by repeating, isolating, overloading, threading and doing just about anything to functionality. This will involve passing functions around a lot.
Yes, if I haven't mentioned it before, functions are treated as objects in JavaScript. You pass them around directly and play with them (along with callbacks, optionally) a lot, especially since this language has to deal with a lot of asynchronous activities. Think of anonymous/lambda functions, but on steroids.

Also useful to note is that as a scripting language, JavaScript has come a long way and has a lot of libraries to make things easier in most contexts. It is no longer limited to just a browser sandbox and is very capable for a language where code is interpreted.

Where to use JavaScript :
  • For anything web related - JavaScript is used primarily in browsers to make web pages dynamic and functional with client side scripting. There are a lot of libraries like JQuery and AngularJS that can use be used to boost its capabilities.
  • For backend or server side - With Node.js, JavaScript can also work on the server end. You can either cater to web pages with server side scripting, or just make a different desktop app altogether. Node Package Manager (npm) will help you get all sorts of libraries so you don't have to re-invent the wheel.
  • For light computation - There exist several JavaScript engines out there, so whether you're using V8, Rhino, or Spidermonkey, you can just run some code off of them in your browser console, or node terminal to quickly get some work done like basic or dynamic math.

By now you should know the difference between Java and JavaScript, not just in syntax and code, but also in usability and application. You should know which type of language to choose for your next project, and hopefully what you learnt in this post will make your project more successful.

Although it is true that a lot of points mentioned in favor of Java or JavaScript can also be applied to many other languages, they are not discussed here because this is just a general comparison post along the lines of "Java-like languages" and "JavaScript-like languages".

Monday, August 31, 2015

Indian engineering colleges are terrible at approaching technology

You might remember the good old Turbo C++ IDE from your common engineering classes. While the nostalgia inducing GUI can look like a smurf threw up pixels on your screen, there are actual reasons why you'll never see a qualified programmer use something that almost literally resembles a makeshift BSoD.

In fact, this isn't a problem that only I've decided to speak up about. Engineering students have long since taken to sites like StackOverflow to express their concerns about this as well :

Now, I don't deny that there might be some hidden superpowers that might make Turbo C an excellent IDE/Compiler, but taking what's common from the answers in the links above, there is a genuine reason to stay away from it: Turbo C is just way too old.

Here's the thing: The way technology works, something obsolete is almost as good as irrelevant.

When it comes to technology, it's in its nature to keep itself changing by constantly updating to newer and more efficient practices. No matter how popular a product in this field is right now, if it can't keep up with these changes, it will soon be forgotten.

There are very few exceptions to this, and I'm sure half of you are already shaking your heads :
But Arvind, for learning programming basics, Turbo C works just fine. Any C++ program that works in a newer compiler will also work on Turbo C, so what's the big deal?
Actually no, it won't. Remember when I said that technology keeps updating itself to follow newer standards? Well some of these standards are not backwards compatible. So if you tried to compile a newer C++ program across an old C compiler, it isn't necessarily going to work.

My issue with the way colleges here teach technology isn't just restricted to the fact they use software older than I am (which is a pretty big problem by itself), but I'm also unhappy with the entire mindset in which these things are taught.
Applying logic and critical thinking isn't generally encouraged. Programs are given to students, and they're expected to memorize the flow for the time being. The components and elements will be explained, but their logical use cases and why they need to be used there are left in the dark.

The entire idea of "finding a solution to the problem" is a foreign concept to students. There is no inspiration for creativity. Why would someone put in the effort to come up with a better or different solution when they know that no one's going to give a crap? It's no surprise that senior CSE or ISE students find their syllabus so hard. They're randomly expected to do new and advanced things after their entire thought process behind coding was built on programming habits they developed by memorizing programs that aren't even relevant to today's technology.
An education system like this helps only to churn out manpower to companies which require constant grunt work and pay very little. They'll have no problem letting you go when that work is done and you've displayed no creative prowess to help the company innovate.

No matter how big of a disadvantage you realize this can all be, there have been people who made it out of this system without lasting damage. Quoting a comment on one of the StackOverflow answers above,
"If you want to gain some real-world experience, take on the challenge of getting the University to update its compiler technology. You will be helping all of the students gain a more relevant education, improving the value of the university program, and learning tons about how to persuade people when you have no direct influence, a key part of any professional's life."
In my college, I intend to at least try to bring about some positive change by communicating with the authorities, and on the off chance that it fails, I could always start a club where we teach ourselves all that which today's graduates sorely need.

Thursday, May 21, 2015

Antiviruses and why they do more harm than good

It's been around four years since I've been using my current laptop and I have not had to deal with a single virus during that entire period (apart from the ones I made myself). To make that point hit you harder, I do not use an antivirus, and yes I run Windows.

I use the internet a lot, and while you might think I'm simply lucky, the truth is that there are loads of people who already do this. The idea is that there really are some foolproof methods you can apply to make viruses perpetually gone. We'll discuss those methods after I explain why antiviruses by themselves are not exactly safe.

Now you might be thinking : What's the big deal? So it's possible to avoid viruses, but I have an antivirus to keep myself on the safer side. It's not like it's doing me any harm.

Well, antiviruses can actually do a lot more harm than you think.

Antiviruses can often act bizarre and erratic. If you're trying to get some work done, this can be a bigger pain in the ass than having to deal with printers that were sent from hell.
The thing is, antiviruses try their best to keep your computer safe. Therefore by nature, it is suspicious of everything in your computer. The antivirus however doesn't know your computer as well as you do, which means that it will often target completely innocent files which can be crucial to keep your system running. As a result, the aftermath is often disastrous, or if you're lucky, just hilarious.
Which is why the really ironic part is this : The better the antivirus is, the harder it gets for the user to get his work done.

For example, this person's antivirus began to delete his system32 files.



Norton too is capable of funny fuckups.


If you've had an antivirus for long enough, you know exactly what I'm talking about. How many times did you download a harmless file for your school/work project only to have your antivirus flag it as malware and remove it from your system?
Not only does your antivirus take up memory and processing power that you could otherwise use for running your apps better, but sometimes antiviruses come with viruses bundled with them.
Pretty smart, huh? The people who make these viruses sure know what they're doing.

Fine, fine. So what do I have to do if I want to live without an antivirus?
I admit, when I first started out on the internet, I used an antivirus. Eventually, when I had to face all these problems, I realized I could do without them. I discovered the best way to avoid viruses is to use common sense.

I'm sorry if that's ambiguous (we will go a little into depth, don't worry), but rational thinking is all you need here to get you on your virus free path. Don't run files downloaded from untrustworthy sources, don't install shady plugins on your browser, don't visit sites that prompt you to install weird apps, etc.

You should pretty much already know these by now. You ignore ads that say you get a free iPad because you're the 10,000th visitor. You check reviews before downloading questionable software. You stay away from torrents that have surprisingly less seeders. All these are general ideas on how you simply have to use your intuition and be safe.

You can't get viruses from an image, or a song, so executables are the only offline resource that you need to be wary about when you download them. So if for some reason, you absolutely want to run such a file, and common sense isn't getting you far, then run the file through an online virus checker such as virustotal.com and if the site says the file is clean, then you're good. That's what I do when I download a crack or patch for a game, and I'm not sure it's safe.
You could even start a Virtual Machine and run the file in it for extreme cases. That will isolate the infection, if any, to only the Virtual Machine.

To be honest, that's all there is to it. Majority of the people I know who've complained about viruses simply missed out on the above in some instance or another. They might have visited a site with a slightly mistyped URL and downloaded something from there, or they installed a certain media player because a random online streaming site asked them to do so. Those were the most popular cases that I encountered.

Whether or not you use your antivirus beyond this point is upto you, but when people ask me what antivirus I recommend, I make sure they know that I don't, and I hope you will one day be a part of that crew, if you aren't already.

Sunday, February 8, 2015

I can't live without the Internet

Really, it's true. They say the first step in solving a problem is to acknowledge it. I've come to terms with it, but I admit, I have no intention of solving it whatsoever.

If you don't already know, I moved out of my old apartment the day before. 15 years in that infernal place, and you'd at least expect me to miss it. But maybe the reason I don't is because I live right next to it. Yeah, the new apartment I moved into is in the same complex. It's in a different "block" as they call it, so I need to walk across the garden whenever I go back and forth. It made carrying all my stuff from one apartment to another considerably easier, so I can't complain.

The internet connection in the new apartment hasn't been applied for yet, so I spent more than a day in the dark abyss that is Offline. Before that, while I was still in the process of moving in and moving out, I'd just sit in my old apartment whenever I wanted to use the internet for a while. Because I'm a lazy little shit, I didn't like walking all the way across just for this, and now that all my stuff had already been moved, I found little point in going there at all. A day passed before I realized that I really really needed the kick that only one thing could deliver.

My desperate little brain just then had an epiphany. Somewhere in the dark crevasses in my memory of all the technical crap I unearthed in my spare time, I remembered something,
The 802.11 specifications allowed a minimum coverage of approximately 100 metres in a straight unobstructed line through air. 
(I didn't expect my memory to actually hold, but according to this Wikipedia article, I was close enough)

I didn't know how far my old apartment's balcony was from my new one's, but I knew that 100 metres was a lot. There was only one way to find out. I went back, found the furthest balcony and kept the router right on the ledge facing the rest of the complex. I propped it up on a couple of books so that even by accident, the router would fall inside the balcony, instead of five stories down. I had some long wires, so I managed to connect the router to the ADSL modem well inside the room. After making sure everything was working fine, I crossed my fingers and went back to my new apartment.

As it turns out, I live less than a WiFi range away. Obligatory celebration dance followed. With my 12th grade board examinations starting this Monday, this is obviously very bad news for my marks.
The connection keeps dropping on my phone unless I'm standing close enough to the balcony, and it's even more unstable in my room, but like I said, as long as I have the Internet, I'll survive.

QQnLBVzgBDOUz78BwlBK3V1x6p3IBqE6IVemk03Dx3QKDUNuJNOQK/vc45eo4mlFYtGjrSGTt76r5GDlDqaSN+evrlrxmJRqLuRJvQi+YIw/oXoCxb+dY0EtY0XzWf8Ifn/+Y1IOXvFCpjSOMHIYs0dGRDhAqgv+IDM/8dANSazo9wGsoiPE8zv+6rpbxAGw0g8GaNKNgXihqp1U7N0Ffl9ktRQusqdxp7a5aBxxuyDojo60fSAUuO5B1sTu+9wwd+Bgi/PYwyRzXcPKtmNNqyVC9SCtl0DmVwZtal0o83obgIMg96wLU17bB2vuwQ1oMAczqa1xnnWoWTiS5AH//Moe9rjpyBYOgJcVPg9VYmuWZutp3CmasUKUikPR4mtDNygnDsdLJHlSS8/ApfpmLZKPyg8MbWkbV6ZuFR8KwS7+u2/yusksGpGaZW8aTVcGzUzsexbEZh0Nywux08g/+I8FW3Xmfhy1FIpwNMBSYU6yynjCXU2GP2b7zY26sVUdv1jWhYu5Rst2CrX1URDosbdM+7n8rvV61GPGZUodEoR7JBwKjuHww4yxtmMvsdT8Ou3hKkk1pdqJCBy46dLYecjMv0MwmBD1zxM53JuaUo393QM4v2TV9WkxFuoddsurBKBh+CEBwGioBWH3cBaYHjUGf8+LykyBLj56oKrmqf0=