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

Monday, 12 December 2016

Introducing the Crystal Programming Language

It's a dream come true!

Wouldn't it be great if interpreted languages, like Ruby, could be compiled? Also, I hear many people complain that Ruby's dynamic typing makes it weak. This is exactly where Crystal literally shines!

What is Crystal?

 

Crystal is a compiled programming language which is syntactically very similar to Ruby. Most Ruby programs would compile fine under Crystal with minor modifications.

The advantages of using Crystal over Ruby are:
  • Crystal is compiled. Compiled code runs much faster than interpreted code. As a result, time-critical programs can be written in a language which is as slick as Ruby.
  • Crystal is statically typed, i.e., all variables have a type. Despite this, Crystal doesn't require you to assign a type to each variable; the process is automatic.
  • Crystal can call C code. In other words, you can embed C inside Crystal.

Why you might wanna use Ruby over Crystal:
  • Crystal is a newbie. Development began in the mid-2011 and was officially released in June 2014. Crystal is still in its alpha stage.
  • Crystal is not 100% compatible with Ruby. Any non-trivial Ruby program would require changes to become Crystal compliant.
  • Poor support for Windows OS. This is the usual issue with almost all open-source projects: they don't give a damn to Windows and Microsoft.

How to use Crystal?

 

Crystal uses The LLVM Compiler Infrastructure for producing native executable files. I will be talking more about LLVM some other day.


Installing Crystal


I mentioned already that Crystal and Windows don't go well together. In this section, I will explain how to install Crystal on different *NIXes. At the end, I will tell you what can be done on Windows.

Clear and concise installation instructions can be found here: https://crystal-lang.org/docs/installation/index.html

Windows


You can try one of the following workarounds on Windows. Neither is guaranteed to work!
  • Install Cygwin and try building Crystal from source.
  • If you just want to try Crystal, you can do it here: play.crystal-lang.org

Using Crystal

 

Crystal can be used from the command-line. For an introduction to command-line for beginners, see Introduction to Command-line For Complete Beginners.

To execute a program immediately without generating an executable file, run this command:

$ crystal run sourcefile.cr

To create an executable program, run the following commands:

$ crystal build sourcefile.cr
$ ./sourcefile

There are other commands as well along with numerous command-line switches. For the complete guide, look here: https://crystal-lang.org/docs/using_the_compiler/index.html

Hello, World!


Open up your favorite text editor (Vim for me) and save the file as hello.cr with the following contents:

puts "Hello, World!"

Run the following commands in the terminal:

$ crystal build hello.cr
$ ./hello

Neat, right?

Let us know what you think about Crystal in the comments. You can also suggest additional features or support, I will forward them to the Crystal development team.

Tuesday, 1 November 2016

Which Programming Language Should I Learn First

Popular Programming Languages

The Ideal First Programming Language

 

Our society runs on software and programming is how those softwares are created. Today, programming is being used in a wide range of different fields; from scientific research to commercial softwares. There are many different programming languages, each of which is used in a different domain of its own. There are also many different types of programmers. Still, searching the web reveals that most articles discussing the topic of an ideal first programming language don't take these facts into account! 

In this article, I will discuss, taking all the current factors into account, what programming language should you start with. In my opinion, the choice of the first programming language depends not on its difficulty but on what type of programmer you want to become. In fact, many non-programmers, like scientists and statisticians, often have to program.

Why Learn Programming? 

 

Other than being a high paying job, programming helps you become a better mathematician and problem solver. Programming works like magic for non-programmers; a scientist can perform better with the knowledge of programming, a statistician can visualize his data and find secrets buried inside the data by coding.

Even if you never intend to program, learning the basics of programming can help you understand the myriad of tech surrounding you better. You would know the truth behind what others believe is magic.

Most, if not all, high paying jobs require knowledge of computer science.

How Should One Learn Programming?

 

Programming is an art, just like music, painting, swimming, etc. And just like those fields of art, programming demands your complete devotion. If you try to learn programming in 21 days, you will miss a lot of vital experience which you could have gained had you learned programming in 21 months. Do you expect a musician with 21 days of experience to perform well, let alone perform presentably? A 21 days programmer is synonymous to it.

One thing that distinguishes programming from other forms of art is its interactiveness. You code and get the result. It requires less time to get started with compared to music. A 21 days programming book may get you started but doesn't teach you programming.

Which Programming Language Should I Learn?

 

Consider this question for a minute: If you were a professional traveler, which language would you learn? Probably, you will need to learn most of the popular and important languages. On the other hand, if you are not a traveler and have to go to Italy, learning Chinese will not be very helpful.

In the same manner, if you are a professional programmer, learning a single programming language is not enough. And if all you want to do is to visualize your data and perform some simulations, learning Assembly won't help you.

Coming to the main question, so which programming language should YOU learn? Here is a short account.

Professional Programmer

 

A professional programmer needs to stay updated with latest technologies. A new programming language appears every year with the aim of improving the life of a programmer. Again there are many types of programmers. In general here is a list of programming languages every programming language should know. The ones with * are more important presently:

  • Java*: It is the most popular programming language.
  • C*: The granddad of most modern programming language.
  • C++: Used by computer scientists and game programmers.
  • Python*: If you work with non-programmers, this is the language of choice.
  • Go: Google's Go is a new player with lucrative promises.
  • Swift: Go's brother, from Apple.
  • HTML*: The programming language of the Web.
  • Bash: If you are into *NIX.
  • PHP: Old but gold.
  • JavaScript: Has taken rebirth.
  • Perl: Was popular, today Python has taken its place. Nevertheless, it is faster than Python in some cases.
  • Ruby: Very much like Python. Used mostly in Web development.
  • C#: Java's ugly sister, from Microsoft.
  • Lisp: On the list, because it is my favorite.
  • Prolog: Used mainly for AI, but has become unpopular these days.

Hacker

 

A hacker is a person, who takes thing beyond limit. So, the fully correct answer to this question would be to learn as much as possible. But for pen testers, the list is quiet small:

  • HTML, PHP, JavaScript, SQL****: These are some of the language used in the development of Web and server side programming.
  • Java: I hate it but it was and still is used in server side programming.
  • Python, Ruby, Perl****: The preferred choice of a hacker when it comes to code something.
  • Assembly, C, C++: These are the languages in which you will find most softwares. Assembly is the last resort though. They are helpful in reverse engineering.

Researcher and Scientists

 

They have the easiest life, at least when it comes to the number of programming languages they need to learn. Although, learning at least two programming languages is recommended, some have done well with just one programming language. I highly recommend you learn all on this list:

  • Python*: One of the easiest programming languages.
  • GNU R: Heaven for those who are messing with numbers.
  • MATLAB: For numerical and image processing.
  • Spark: R alternative. It is better in my opinion, but is not as much supported as GNU R.

Be assured that anything you learn about programming will not be wasted. For millenniums to come, programming is going to be the most important skill. Everyone should learn how to code.


Share you opinion with us in the comments. Have a G'Day all!