Showing posts with label dynamic language. Show all posts
Showing posts with label dynamic language. Show all posts

Monday, September 7, 2015

Installing and Using Ruby Interactive Shell on Windows

      Ruby is dynamic,interpreted, object oriented programming languages which is one of the easiest programming language to learn and with Rails its just might be the best web development option at the moment. Ruby intsallation is pretty much simple in windows, Linux and you don't have to install Ruby on Mac. It already has Ruby installed in it.

   Step by step guide to install Ruby on your PC:
  1. Go to Ruby programming language homepage: https://www.ruby-lang.org/en/
  2. Click downloads
  3. Click on Installation-->click on RubyInstaller(Windows)-->Ruby installer-->Download
  4. Select the top selection there that will be the current version of Ruby 
  5. Click save file. let it download
  6. Now double click the file-->accept license agreement-->Install-->finish.

Using Ruby Interactive Shell 

        The interactive shell  or just a shell allows us to type Ruby statements or expressions at the command line and gives immediate result. So open the command prompt and navigate to the folder where Ruby is installed and type "irb".


On ruby shell single number evaluates itself. We can perform simple arithmetic operations the ways show above screenshot. Strings also evaluate to them self, We can perform concatenation operation between two strings using '+' operator as shown below :


     
         We can also store data in variables and use it later as shown in below "greet' is variable which stores value "good morning". After typing good morning it returns "good morning".


   We can also concatenation "greet" with other value 


    We can write more complicated expressions in ruby shell. We can create functions for example square function in bellow example. Here I wrote my own user define "sqr" function to find square of a number.
 
   
     If you have good understanding of function you not even have to write return statement. lets consider following function for addition of two numbers. In which I wrote add method for addition of two numbers when next time I write add(2,2)  it performs addition of these two numbers which is 2+2=4.



Monday, September 16, 2013

Introduction to PHP and its basic syntax

Hi friends, today we will see introduction to PHP and its basic syntax. Prerequisite to understand this blog is to read my previous blog on XAMPP server.
PHP is the recursive acronym for PHP: Hypertext Pre-processor. PHP was developed by Rasmus Lerdorf and now it is maintained by The PHP Group. It is an open source server side scripting language. Pre-requisite for learning PHP is HTML. PHP code can be embedded inside HTML code. PHP is mainly used for web development. Everything in PHP is enclosed in angle brackets
“<?php ……………..?> “.
PHP allows writing web pages which are dynamically generated. When a user visits any of the website which has PHP webpage’s, then a web server processes the PHP code and translate it into HTML page and then send to the requesting client.
PHP’s syntax is very similar to C, Perl, Java beside this PHP code can also contains tags.
PHP code is:
<?php
------
------
?>
PHP code must be saved with the .php extension. We will now see a simple Hello World program written in PHP which will give us basic understanding about the syntax of PHP that we must use.
This simple code is saved in the xampp directory where the path is C:\xampp\htdocs\hello_world.php. We have seen xampp in our previous blog, so start apache server there. And then go to web browser and type localhost/Hello_World.php.
Output:
There are several things to learn from this simple code written above. As we can see, code which is red in colour is the starting and end point of php code. Everything will be inside this code always. Now see line 2, echo is used to print the statement that follows, be careful here to end the statement with semicolon (;).
This is the first blog on PHP and in coming weeks we will learn more about this dynamic language.