Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Saturday, June 25, 2016

The Hackathon Circlejerk

Just like any other competitive activity that exists for students, like sports, or Model UN, hackathons too have their own little culture going. I know this by having attended plenty of these to predict that in the next hackathon I go to, I'm almost sure I'll run into someone I've met at a hackathon before.
However, I'm not convinced that's a good thing. For the sake of all students out there who still have the inspiration to get something meaningful done in their life, I sure as hell hope this doesn't become the next big trend among them unless the way hackathons work start to change, and I'm more than happy to explain why. Let this be a comprehensive guide to hackathons and what's currently wrong with them.
(I hope to cover every vendetta, personal or in general, that I hold against hackathons, so bear with me if this article is a little long)

You could argue that working on your own cool little project for 24 hours among other creative people with free food and drinks sounds petty awesome. And honestly, that would be true if hackathons were fair and perfect.
Unfortunately however, most of them are not; and all the people who frequent hackathons regularly know this as well.


That said though, some hackathons are not so terrible and are actually worth participating in. I'll start with the drawbacks of how hackathons work today, and move on to which ones you might consider going to.

Oh, the horrors


A "hackathon" in today's terms is a horrible combination of:
a) organizers who want to make money,
b) sponsors who want to shamelessly promote their brand which at times isn't even relevant to the event,
c) judges who want to steal ideas that have merit for their own company from unsuspecting college students (I'm obviously exaggerating, but it has happened before), and
d) participants who want to bring their month or year old finished product and compete so they can get an easy win.

So why is the system this bad? This kind of characteristic "circlejerk-esque" behavior is usually the result of an avalanche of moral decay caused by one bad persisting feature after another, such as :

  • Restrictions on creativity :
    • Not a single hackathon that I've been to has encouraged the idea of simply hacking together a neat project. Kind of ruins the central philosophy behind a hackathon, doesn't it? The criteria for winning involves "what can sell" instead of "what is fun". I understand why this might be necessary but maybe the reason why hackathons have such a bad stigma is because they're so unnecessarily commercialized. This has been the biggest shock for me since my first hackathon and I'm still adjusting to it. To me, any good idea has merit regardless of whether or not it can make someone money. This can easily be solved by having an open mind while judging or having a more relatable panel of judges altogether. An example of a parody hackathon that was a great satire against this problem was The Stupid Hackathon.
    • A lot of hackathons have a "theme" that your project is supposed to comply with. That's fine with me, but the shitshow starts to surface when you have to use a certain platform/technology/stack by mandate. These are usually not announced prior to the hackathon commencing and even if you don't have to use it, they provide you some incentive to, which still sways a lot of the participants out of greed to win. This usually happens by intervention of the sponsors and can be solved by keeping the event agnostic to the sponsoring agent.
  • Unfair practices :
    • An overwhelming majority of hackathon winners are people who've begun well before the 24 hour time limit. A lot of people use hackathons as a break from their lives to come together and hack something new and innovative, and people like these who bring their already existing projects into the mix just ruin the spirit altogether. You can't confront them about it either as there are no specific rules in place about the shameless lengths you can go to for winning. Pre-screening projects before submission might be a small fix, but there needs to be a proper solution to this before hackathons turn into a cheap platform to just shout out your startup ideas into an indifferent crowd.
  • Bad commercialization :
    • You are judged by your presentation, not your project. As mentioned before, the judges are almost always swayed by profitable ideas instead of innovative solutions. This is because companies have stopped seeing hackathons as technical endeavors, so they send out people from marketing to judge. As a result, participants with strong presentations are seen as better candidates even if their technical stack aren't even in working condition. Sponsors need to start sending out actual developers and engineers who factor in things like code complexity and technical implementation in selecting the winners.
    • Sponsors don't hesitate to shamelessly advertise themselves right in your face. Sure, I don't mind a brief intro and mentions about technologies I might actually use, but that rarely ever happens. The hackathon might have begun 12 hours ago, but there will still be a guy on stage talking about some weird product or API that has absolutely nothing to do with the hackathon or any of its themes. In retrospect, this is a bit sad to see because no one gives him/her any attention despite them having paid to be a sponsor for the event. Involving only strictly relevant sponsors doesn't sound like an impossible thing to do.
    • Sucking up is more common than it should be. "Open hacks" aren't really open, all it means is "we'll let you code whatever you want, but we'll only favor those that are relevant to the sponsors". As ridiculous as it is for hackathons to expect you to "solve healthcare in 24 hours", it doesn't matter even if you manage to do so, because your neighboring team who wrote a bot with the sponsoring company's API is going to win. I get that there's always going to be some bias or the other from the judges, but maybe the sponsoring and judging entities should be kept isolated for this reason.
  • Bad hygiene :
    • As an 18 year old, going a day or two without sleep might be alright occasionally, but that can soon take a toll on you. Unfortunately, most hackathons encourage you to stay up and push through (even if they don't actually say it), and then act surprised when everyone seems too tired to present their ideas the next morning, and those that do, deliver unenthusiastic and mediocre presentations. This can be solved by increasing the duration of the event, and just having all the participants leave at night, or just halting the event altogether at midnight by turning the lights off and insisting that everyone gets some sleep. Few hackathons have successfully done this before.
    • Junk food is pretty much the go-to solution for hackathons these days. Organizers have started to tie in with indoor caterers or simply bulk order from freshmenu for example, but I'd really like to see this done throughout in other smaller hackathons too.


But they're not all that bad


If you absolutely insist on attending a hackathon or have already been sucked too deep into the culture to quit, there are ways to find out the few that provide a decent experience.

First off, avoid hackathons at colleges or other institutions. They are a perfect example of every horror I've listed above. If you replace professional organizers with a student body, you can't really expect anything different. Do not waste time in one of these unless it's a hackathon happening in your own college, and you don't mind killing a night with your friends.
Second, look for "branded" hackathons with a good reputation through the years. My city doesn't have many of these, but I'm aware that some of the hackathons in the US (some even from institutions) can be a fun experience as they've dealt with and refined the same problems over years and have pretty much turned hackathons into art at this point.
If you can't find anything like that, look for hackathons with only one sponsor overall. You can always tell these apart by the name of the event. You don't need to be a genius to know that the InMobi Hack Day is sponsored primarily just by InMobi. You still might have to deal with biased judges in this instance, but there at least won't be a conflict in themes and commercial interests. You can rest assured that they can afford to have more professional organizers who will help you out better when the need comes.
Lastly, if you do settle on a hackathon, call them up and inquire about the themes, the meals and the winning prizes. If they can't answer any of those questions or tell you that they will be answered at the event, you should consider calling it quits as any reason for doing so is almost always a bad one. This also helps to get a measure of how good or bad the organizers are going to be in general.

If you've finally settled for a hackathon that you're going to attend, whether a good or a bad one, here's a few a good things you can expect along the way :

  • Learning : No matter how simple your idea is, you're going to be surprised how awfully difficult it can be to set things up when you're coding live. You're going to run into bugs you didn't even know could exist, and when it's not a bug, it will be a logical flaw in your planning itself. Dealing with these things under pressure is really an experience and will make you a better developer by the end of it all.


  • Networking : Probably the biggest resource in a hackathon are the people around you. Go ahead and talk to the people and find out what they're hacking. You never know who among them could end up being a future teammate or help you get an internship.
  • Actually build something : You and your friends will come up with a lot of crazy ideas over time and in your leisure, but how many of them are actually worked upon and completed? A hackathon is a really nice way to actually get people together and work on an idea that you've always had. It serves as a social event, and at the same time isn't quite, so you can use it as a convenient excuse to take a small break form your other commitments and responsibilities momentarily.
  •  Bragging rights : Of course, winning a hackathon is always such a sweet feeling. Depending on how popular the hackathon in question is, it could also serve as a neat little badge on your resume. If the winning prize turns out to be decent too, that would be the icing on the cake.


I'm not playing Devil's advocate here though. My overall opinion was and still is, that hackathons suck.
If you've never been to a hackathon, or even fully understand what a hackathon is, that's good because you can't miss something you've never had. Next time someone invites you out for a random hackathon that doesn't match the above criteria, you can take the opportunity to laugh and promptly walk away. You're not missing out on much, I promise. Even if you have this insane idea for an app or website that will floor any competition, the experience of a hackathon is hardly worth the measly prize at the end of it. I'd advise you to just gather a bunch of enthusiastic people and try your luck as a startup instead. Even if it doesn't take off, your productivity and experience with reality along the journey will thank you.


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.

Friday, November 21, 2014

The new enkrypt.in is here

After more than a year of rigorous development, the new interface is finally out in the open.
Well I'll be honest, the reason it took me so long for this project was because I have a surprising talent for automatically procrastinating. My daily work cycle includes spending the day with the editor in the background, buried by every distraction the internet has to offer; and then pushing code after midnight at a rate that is not recommended for the healthy. I've lost count of how many sleepless nights this website now owes me, but I am indeed glad that it's finally fucking over.


Procrastination wasn't the only thing that held me back though. I did run into a dilemma halfway through the development process. My web host got taken down a couple of months ago (The host was not owned by me), and that's when I realized that I needed a permanent hosting solution instead of migrating from one free host(er) to another.
So now came the issue of retrieving backups from the expired host, painfully shelling out money to buy some new server space, and then configuring it right to host my website (If I ever somehow finished it). Of course, I did finally finish it, but I also bought a sweet VPS for myself from Digital Ocean along the way.

If you haven't noticed yet, my proudest part of enkrypt.in is the way I've made everything dynamic. Page reloads and statically loading content is for wimps. I hand coded most of what you're seeing with the use of barely any plugins. The site design is completely of my creation but I now wish that I'd used some already existing plugins to help me out and save all that work. There's a lot of PHP, a lot more of Javascript and some HTML from me that's holding this place together.
There are still possibly tons of bugs throughout the site even though I think I've smoothed out most issues, so if you're the kind of guy who likes to toy around with fragile, poorly protected webpages for vulnerabilities, then by all means go ahead. But even if you're not, please let me know if you discover a bug, glitch or error that's not supposed to be there so that I can fix it at once.

I again haven't written a blog post in more than a year because I'd promised myself not to, until I'd finished my site since my blog's being integrated into it. So now that that's done, I'll hopefully stick to my new rule: of keeping my content short. (some of my previous posts were way longer than they needed to be), and posting more often.

Well there should be a good amount of content here on this site for you to go through, and hopefully some will interest you. If you like what I've made and think this is neat, there should be some Like, Share and Plus One buttons on this page that I would really thank you for using.

Saturday, December 15, 2012

Tic Tac Toe - Unbeatable Algorithm

This post is part of the "First Few Old Blog Posts" archive.
You could expect a certain lack of coherency/maturity from these posts.

For my Computer Project at school , I had to make a simple Java Program. The rules although simple, were very restricting since my class hadn't learnt as much in programming, The program had to be console based (i.e. no Graphics), I could not use any Library Classes apart from the ones that came along with java.lang and Console Input classes. Also, my class hadn't learnt about inheritance and other OOP stuff so I had to stay clear from those too.

The trouble now was to make a good enough project that fit the criteria.
My classmates had settled on making games such as hangman, crossword, calculators etc, but I had already made most of them before while I was getting into programming, and they didn't have much appeal to me.

In the end , I concluded that the project would have to be small anyway, so I decided to make Tic Tac Toe Singleplayer. I'd already made Tic Tac Toe mutliplayer last year as part of a larger package , so I thought that it would be a nice addition to have this as well.

The 3x3 grid was constructed using a 2 dimensional array.
You had to play against the computer in 3 modes - Easy , Medium and Hard respectively.

Easy mode was simple. I used Math.random() to decide the X and Y co-ordinates of the resulting move.

Medium randomly chose between playing easy or hard for that move.

And hard used an algorithm that was impossible to beat. Of course , tic tac toe isn't such a full blown game , and any person smart enough could play any number of matches and always make a tie. But anyway, here is the code for all 3 modes.

Note: This is a function that simply calculates the position that the computer plays in, in a given circumstance. It takes an integer value (int c) that contains the difficulty value (1,2 or 3 for easy,medium or hard). It also takes a 2 dimensional character array of length 3 and 3 (char[][] u) which contains 'X' (player value) , 'O' (computer value) or '-' (empty value). The function returns an integer array of size 2 which contains the x and y co-ordinates of the computed value.

To see the whole program , click here.

     
    public static int[] compute(int c,char[][] u){
        int ar[]=new int[2];
        if (c==1){
            int x=(int)(Math.random()*3);
            int y=(int)(Math.random()*3);
            if (u[x][y]=='-'){
                ar[0]=x;
                ar[1]=y;
                return ar;
            }
            else{
                return compute(1,u);
            }
        }
        if (c==2){
            return compute(((int)(Math.random()*3)+1),u);
        }
        if (c==3){
            boolean mark=false;
            int x=0,y=0;
            int count=0;
            for (int i=0;i<3;i++){
                for (int j=0;j<3;j++){
                    if (u[i][j]=='-'){
                        count++;
                        u[i][j]='X';
                        if (check(u)==2){
                            mark=true;
                            x=i;
                            y=j;
                        }
                        u[i][j]='-';
                    }
                }
            }
            for (int i=0;i<3;i++){
                for (int j=0;j<3;j++){
                    if (u[i][j]=='-'){
                        u[i][j]='O';
                        if (check(u)==1){
                            mark=true;
                            x=i;
                            y=j;
                        }
                        u[i][j]='-';
                    }
                }
            }
            if ((!mark)&&(predict(u,0,0)>1||predict(u,0,2)>1||predict(u,1,1)>1||predict(u,2,0)>1||predict(u,2,2)>1)){
                for (int i=0;i<3;i++){
                    for (int j=0;j<3;j++){
                        if (u[i][j]=='-'&&((i==0&&j==1)||(i==1&&j==0)||(i==1&&j==2)||(i==2&&j==1))){
                            u[i][j]='O';
                            for (int k=0;k<3;k++){
                                for (int l=0;l<3;l++){
                                    if (u[k][l]=='-'){
                                        u[k][l]='O';
                                        if (check(u)==1){
                                            mark=true;
                                            x=k;
                                            y=l;
                                        }
                                        u[k][l]='-';
                                    }
                                }
                            }
                            u[i][j]='-';
                        }
                    }
                }
            }
            if (!mark){
                if (count==9){
                    int ran=(int)(Math.random()*5);
                    switch(ran){
                        case 0 : x=0;
                                 y=0;
                                 break;
                        case 1 : x=1;
                                 y=1;
                                 break;
                        case 2 : x=2;
                                 y=2;
                                 break;
                        case 3 : x=0;
                                 y=2;
                                 break;
                        case 4 : x=2;
                                 y=0;
                                 break;
                    }
                }
                else if (count==8){
                    if (u[1][1]=='-'){
                        x=1;
                        y=1;
                    }
                    else{
                        int ran=(int)(Math.random()*4);
                        switch(ran){
                            case 0 : x=0;
                                     y=0;
                                     break;
                            case 1 : x=2;
                                     y=0;
                                     break;
                            case 2 : x=2;
                                     y=2;
                                     break;
                            case 3 : x=0;
                                     y=2;
                                     break;
                        }
                    }
                }
                else{
                    if (u[0][0]=='-'&&u[2][2]=='O'){
                        x=0;
                        y=0;
                    }
                    else if (u[2][2]=='-'&&u[0][0]=='O'){
                        x=2;
                        y=2;
                    }
                    else if (u[0][2]=='-'&&u[2][0]=='O'){
                        x=0;
                        y=2;
                    }
                    else if (u[2][0]=='-'&&u[0][2]=='O'){
                        x=2;
                        y=0;
                    }
                    else{
                        if (u[0][0]=='-'){
                            x=0;
                            y=0;
                        }
                        else if (u[2][2]=='-'){
                            x=2;
                            y=2;
                        }
                        else if (u[0][2]=='-'){
                            x=0;
                            y=2;
                        }
                        else if (u[2][0]=='-'){
                            x=2;
                            y=0;
                        }
                        else{
                            for (int i=0;i<3;i++){
                                for (int j=0;j<3;j++){
                                    if (u[i][j]=='-'){
                                        x=i;
                                        y=j;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (u[x][y]=='-'){
                ar[0]=x;
                ar[1]=y;
                return ar;
            }
            else{
                return compute(3,u);
            }
        }
        return ar;
    }


Well, I admit that this algorithm isn't the most efficient one out there, but I had functionality in mind, instead of efficiency, so I rolled with a makeshift solution.
But what's more fun is to tell everyone that you couldn't beat my program the next day at the computer lab. They enthusiastically take up the challenge at once, and their faces were worth being looked at when most of them lost to the computer at the second game.

It was great fun.