Posted by & filed under Blog Entry.

I and my friend Chandan Mishra started SudoSaints 2 years ago with a team of 5 people.. We have now grown to be a team of 15 people. And the journey from 5 to 15 is a journey that was not easy.

The main problem was, we just weren’t able to find talented people. We still aren’t able to find them. We constantly post on Social media about job openings, keep a look out for anybody with a knack for programming among our college juniors and friend circles, and a lot of other thing. But we just can’t get people with the skills we need.

Our requirements are usually simple and similar to what a lot of start-ups might need. We just need a good programmer who has little experience on either Android or PHP. That is it. Nothing too complex. We don’t mind if you don’t know all the concepts in android. As long as you are willing to pick up and put the effort, we’re good.

Here is how hiring has been for us till now.
1. We post details about the opening on various social media platforms and job portals.

2. We get about 20-30 applicants/resumes per day. Most of them with 2-3 months of experience and some certification from an institute like SEED Infotech, Centre for Development of Advanced Computing or MindScripts Technologies or other such institutes in Pune.

3. We select a few good ones among them. And call them for an interview. And this is what happens.
None of them have their basics of programming clear. A few of then had problems writing the syntax for a simple for loop (There are people who have studied 4 years of IT/Comp engg. and 6months-1Year of certification course in JAVA or Android).

The questions we ask in the first round are basic and simple. Below are few of them with answers.

Q. What is an Activity? (In the context of Android. The candidate had finished 2 months of his 3 months Android Course).
A. It is something we do or we perform.

Q. What is JSON?
A. All the candidates from SEED Infotech answered “JSON is an XML Parser”. And one of then said, “JSON is a tool that converts Website data to XML”.

Q. Difference between ObjectOverloading and ObjectOverriding.
A. They all tell the difference between Function Overloading and Function Overriding. They just know it by definition. No one knows what it is practically.
Very few of them realize that you cannot overload or override an Object.

There are a lot more. But this makes me really sad. If this is the actual status of education/teaching going on, you can’t expect that all the pass outs get a job.

And children just decided to join additional classes to learn programming and spend Lacs of rupees. And that really get them no where. The institutes are just money making schemes. They might have been good once upon a time. Butnow, all of their qualities have been degraded. And the students still believe them.

This is a problem that India needs to solve. With so many start-ups coming up, India needs skilled engineers/programmers. And colleges and training institutes are, in my opinion, not something we can bet on. There has to be a better way.

We need to teach students that the only way to learn something is to do it. Without doing, there is no learning.

Posted by & filed under Blog Entry.

In the coding world, developers are told they should always comment their code, but rarely are they told how to do so. And thus, comments are written just for the sake of it and not because the comment is needed. A lot of developers feel they are doing a great job by adding comments, regardless of the quality.

I’ve noticed this even in a few open source projects. Take the following example

/**

* Constructor
*/
function __construct(){
//Some code
}

 

I would rather like to see comments that actually add value to the code and saves time for the next developer who reads it. Comments shouldn’t be written purely to show we’re “good little programmers.” We should use comments sparingly and mainly to “document the why”.

Next time before commenting, ask yourself a simple question: “If I come back later and read this code, will it be obvious to me why this is written in this way?”. If your future self would be thankful for an explanation, then just put a comment that explains what is being done. Else, let the code speak for itself.

 

 

Posted by & filed under Blog Entry, General, PHP.

Despite of all the bad-mouthing that PHP gets, i personally think that PHP is super awesome. There might be a few issues in the documentation, some methods/functions that are completely useless, etc. But it surely is awesome.

The reason why I think that non-PHP developers think PHP sucks is because of the stupid spaghetti code that they see everywhere. And that is the mistake of some dumb-ass PHP developers who neither use any concepts of OOP nor follow any particular architecture. It’s just plain old PHP that has a lot of files and lots of include or require statements.

See, this is fine if you are doing a small form submission. But if you are building a huge Portal, the you MUST use the OO Programing atleast!
Not many developers use it.

If you are not very familiar with the OO concepts, the go and learn it! And more than that, there are many super-awesome frameworks that help you write better well-structured, object oriented code.

 

Posted by & filed under Blog Entry.

So, I just upgraded my blog to WordPress3.8. I loved the Admin panel. It has a full flat design. Something that the wordpress.com users had got a long time ago.

But the New theme TwentyFourteen is really bad. Its probably the worst WordPress default i’ve ever seen, i mean looks-wise. TwentyThirteen was so awesome. The big header image. The colorful posts. That was really awesome.

Not sure why TwentyFourteen isn’t awesome. Either ways, the admin dashboard is awesome. I’m loving it. ;)

Posted by & filed under Blog Entry, Extension, General, Javascript.

An Extension is a simple way to add additional functionality to Chrome without diving into native Chrome Code.

Creating an extension is super easy if your are familiar with HTML/CSS/JavaScript. If you’ve ever done any web development or created any web page, you’ll feel at home while developing the Chrome Extension.

I’ll take you through the development of a simple chrome extension called Chrome to Phone (C2P) that we recently built at SudoSaints

What the extension does is very basic. It just sends a AJAX request to a server, with the logged in user and the link of the Current tab as data. The server then pushes the link to the android device using GCM.

But in this post, we’ll just discuss about the chrome extension.

The Manifest File

The manifest file is a JSON file with properties and meta data of your application. It contains data like The name of the Extension, the version number, permissions, etc. It basically just declares what the extension does.

Below is the manifest.json of C2P


{
 "manifest_version": 2,

"name": "Browser To Phone",
 "description": "This extension pushes the current tab url's to your registered phone, so that you can continue reading on the go!",
 "version": "1.0.1",

"browser_action": {
 "default_icon": "icon.png",
 "default_popup": "popup.html"
 },
 "icons": {
 "16":"images/icon-16.png",
 "48":"images/icon-48.png",
 "128":"images/icon-128.png"
 },
 "permissions": [
 "http://aws.wpcoach.in/",
 "https://accounts.google.com/o/oauth2/token",
 "https://www.googleapis.com/oauth2/v1/userinfo",
 "storage", "tabs"
 ],
 "content_scripts": [
 {
 "js": ["jquery.min.js"],
 "run_at": "document_start"
 }
 ]
}

The above JSON file is pretty self-explanatory. I basically requests permissions to access data from a few websites, the icon set for the extension, specifies the HTML file that should pop-up on click of the icon, and the JS files related to the extension in content_scripts.

So it is obvious that you’ll now need to create the popup.html file and also will have to include some image for the icons. You’ll also need to download jQuery and save it in the same folder as the extension.

Loading the Extension in Chrome

  1. Visit chrome://extensions in your browser
  2. Check the “Developer mode” check box in the right-hand corner.
  3. Click “Load Unpacked Extension” and select the directory in which your extension files live.

You can now see your chrome extension in your Google Chrome Toolbar, on the top-right side. When you click on the extension, you can see the contents of popup.html shown in the popup.

chrome-extension

That’s it! Our extension is now running. All we need to do now is to send the AJAX request to the server.

Since that is something every web developer is familiar with, I’ll leave you to it. Try implementing and let me know how you did it in the comments section.

I’ll make the code available on GitHub soon so that you can check it out! For more details on how to develop extensions, check out Google Developers Website

Posted by & filed under Blog Entry, Wordpress.

So, WordPress 3.7 Beta is out, and there are 4 cool new features.

 

1. Automatic Background Update.

So, until WordPress 3.6, whenever a security update was released, we had to manually update it. But its going to happen automatically from 3.7 onward. That is a boon for many developers!

For those who don’t know, Security updates are the minor releases, like 3.6.1. Version 3.6 is a major release, but version 3.6.1 or 3.6.2 are minor releases, aka security releases. So, no need to worry about the website breaking down because of an automatic upgrade.

2. New Password Meter

WordPress now uses a new password meter, zxcvbn borrowed from Dropbox. I tested it out and the password meter is surely strong.

3. Better Relevant Search Results

Search has been a weak area for WordPress for quiet some time now. Now the core team has worked on Search to make it better. “Search results are now ordered by relevance” rather than just by date. So, when your keywords match just post titles and not just content, they’ll be pushed to the top.

4. Updated WP_Query

The last feature is the updated WP_Query which will provide options for more advanced queries based on Date. I am yet to test this.

If you want to test the Beta release, you can download it from here.

I’ve set up the new beta at varun1505.com/wp37 to test out the new feautres. I’ll post about my tests soon.

Posted by & filed under CodeIgniter, ORM, PHP.

The Model View Controller is a software architecture which separates the representation of the information from the user’s interaction with it.  The architecture, as the name suggests, contains 3 main components. viz. The Model, The View and The Controller.

Model-View-Controller

The Model

The model is the component that holds all the business logic. The model is responsible for manipulating the data, handling the database, structuring the data for the view, etc. In classic MVC, the model notifies the view about any change in data.

The View

The view is the presentation layer for the system. The view takes care of all the presentation related stuff.

The Controller

The controller basically sends commands to the model to update the models state. It also sends commands and data to the view to represent the data received by the Model.

How to use an ORM in an MVC styled application?

If you are using an ORM (as discussed in a previous post) in your MVC styled application, The ORM will be responsible for generating your Models completely. They are actually called entities in the ORM, but they are the Model classes.

MVC with PHP

It is impossible to write classical MVC in PHP. Any framework which claims you can, is lying to you. To implement a classical MVC it would require your Model to inform the View about the changes, which too is impossible in your plain PHP page (you can do something close to classical MVC, if you use sockets, but that’s impractical for real website).

There are 4 other MVC-inspired solutions for Web development.

1. Model2 MVC
Model 2 MVC is a design pattern for web applications in JAVA. It basically separates the display of content from the Logic.

2. MVVM – Model View ViewModel
MVVM is aimed at UI development platforms which support the event driven programming. Here, the Controller is swapped out for a ViewModel, which is responsible for the translation between View’s expectations and Models’s logic.

3. MVP – Model View Presenter
MVP is probably the closest derivative of classical MVC where the Presenter requests information from Model, collects it, modifies it, and passes it to the passive View. This is what most PHP frameworks pass as MVC.

4. HMVC – Hierarchical MVC
HMVC is a very distinct variation of Model2 where the controllers have the right to execute sub-controllers. This gives modularity but hits performance badly.

Frameworks like CodeIgniter and Zend use the MVP architecture. i.e. The client (web browser) requests are sent to the Presenter. The Presenter requests information from the Model, manipulates it a little bit and passes it to a view for Display.
Most of the code I write in based on CodeIgniter, so most of the posts on this blog will follow the MVP pattern.

Posted by & filed under CodeIgniter, PHP.

So there is this hype that ORMs are the solution to all your Data Access problems. They may not be the total solution but they sure make your Data Access easy.

At a very high level: ORMs help to reduce the Object-Relational impedance mismatch. They allow you to store and retrieve full live objects from a relational database rather a set or rows.

What Does it Give me as a Developer?

For starters it helps you stay DRY. Here, your schema is the boss and your models are automatically generated based on the schema.
ORMs generally handle the marshaling the values of individual columns into the proper types so that you don’t have to manually serialize them.

How will my code differ from the individual SELECT statements that I use now?

Since ORMs usually return individually formed objects, you’ll be able to access related objects using attribute access rather than writing another query for it. You’ll be able able to write queries if necessary, but form most CRUD operations, the code becomes simpler.

What about the DB schema and Model Classes?

Most ORMs come with configuration tools inspect your DB schema and create the DB tables for your. Also, many of them give the option to generate the Getter/Setter methods in the Model Class that help you interact with the objects in the Database.

I’m a PHP developer, What ORM should I use?

Doctrine is probably the best ORM available for PHP. Although there are many others which provide different kind’s of functionality.
Most people consider CodeIgniter’s Active Record as an ORM tool. I am not sure if it actually fits in completely, But it sure does make the development process easier.

We’ll be exploring more about PHP ORM’s in the following code and mostly about how to use Doctrine with CodeIgniter.

Posted by & filed under CodeIgniter, PHP.

As discussed in the previous post, a better way to load a template is by using a helper function, which loads the header and footer (and any common partials) for each page.

Here’s how our template helper will be.


if ( ! function_exists('renderPage')) {
function renderPage($view,$data){
           $ci = &get_instance();
           $ci->load->view('header');
           $ci->load->view($view,$data);
           $ci->load->view('footer');
       }
}

Save the above code to application/helpers/template_helper.php file.

To use the helper, we do the following in the controller


function home(){
   $this->load->helper('template');
   renderPage('home',array('key'=>'value'));
}

This will load the view we want, without us needing to load the header and footer manually each time.

To make it even easier, you can autoload the helper in config/autoload.php. You’ll not need to load the helper in every controller.

Next, we’ll see how to create WordPress style functions like get_header() and get_footer() for CodeIgniter.