Olgun DUTKAN

Olgun DUTKAN

Senior Developer

How I became an engineer by going to a business interview #episode1

How I became an engineer by going to a business interview #episode1

I go to the business interview and they are doing the technical exam. You have to listen to all question asked to you. It is really important. Doesn't matter the correct answer. Listen and keep to mind. I do that. When finished my interview, I search the answers to the questions. I learn new things and the right way. I talk about, that questions in this series. Let's begin...

"What is the difference between PHP and NodeJS?"

PHP is a programming language. NodeJs isn't a programming language. NodeJs is rather an interpreter of Javascript code to the operating system installed on the server. PHP and Javascript are script language. But these languages have much difference. I wrote same difference in the following.

  1. Syntax
  2. Both the programming language has access command line interface.

    php -i
    node

    This snippet prints ‘Hello World’ in PHP:

    echo "Hello Wold!";

    This snippet prints ‘Hello World’ in NodeJs:

    console.log("Hello World!");

    Loops, conditionals, and other functions have same syntax difference.

  3. Software stacks
  4. PHP is regularly run on the server-side. But NodeJs is run both server-side and client-side. Because NodeJs is Javascript based.

    PHP needs to a web server, like Apache or Nginx. NodeJs doesn't need to the web server or another component.

    PHP's software stacks like the LAMP stack (Linux, Apache, MySQL). NodeJs's software stacks like the MEAN stack (MongoDB, Express.js, AngularJS).

  5. Synchronous vs Asynchronous
  6. PHP is synchronous

    <?php
        echo("Before the first file is read.");
        $fileContents = file_get_contents("sample.txt"); // You can't do anything while the file is being read, your script is 'stuck'.
        echo("After the first file has completed reading.");
        echo("Before the second file is read.");
        $fileContents = file_get_contents("sample2.txt"); // You can't do anything while the file is being read, your script is 'stuck'.
        echo("After the second file has completed reading.");
        
        /* Output always looks like this:
        Before the first file is read.
        After the first file has completed reading.
        Before the second file is read.
        After the second file has completed reading.
        */
    ?>
    
    

    NodeJs is asynchronous

    console.log("Before the first file is read.");
    hypotheticalFileGetContents("sample.txt", function(fileContents){
    // fileContents now contains the file contents, this function is only called when the file read in the background has finished
    console.log("After the first file has completed reading.");
    });
    
    // You've now told it to start the first read, but it won't 'block' your script execution. It will do the read in the background, and immediately move on with the rest of your code.
    
    console.log("Before the second file is read.");
    hypotheticalFileGetContents("sample2.txt", function(fileContents){
    // fileContents now contains the file contents, this function is only called when the file read in the background has finished
    console.log("After the second file has completed reading.");
    });
    
    /* Output could look something like this:
    Before the first file is read.
    Before the second file is read.
    After the first file has completed reading.
    After the second file has completed reading.
    */
    
    

Aug 7, 2017