Why Learn Perl, Python, Ruby If the Company Is Using C++, C# or Java as the Application Language

Why learn Perl, Python, Ruby if the company is using C++, C# or Java as the application language?

A lot of times some quick task comes up that isn't part of the main software you are developing. Sometimes the task is one off ie compare this file to the database and let me know the differences. It is a lot easier to do text parsing in Perl/Ruby/Python than it is in Java or C# (partially because it is a lot easier to use regular expressions). It will probably take a lot less time to parse the text file using Perl/Ruby/Python (or maybe even vbscript cringe and then load it into the database than it would to create a Java/C# program to do it or to do it by hand.

Also, due to the ease at which most of the dynamic languages parse text, they are great for code generation. Sure your final project must be in C#/Java/Transact SQL but instead of cutting and pasting 100 times, finding errors, and cutting and pasting another 100 times it is often (but not always) easier just to use a code generator.

A recent example at work is we needed to get data from one accounting system into our accounting system. The system has an import format, but the old system had a completely different format (fixed width although some things had to be matched). The task is not to create a program to migrate the data over and over again. It is to shove the data into our system and then maintain it there going forward. So even though we are a C# and SQL Server shop, I used Python to convert the data into the format that could be imported by our application. Ultimately it doesn't matter that I used python, it matters that the data is in the system. My boss was pretty impressed.

Where I often see the dynamic languages used for is testing. It is much easier to create a Python/Perl/Ruby program to link to a web service and throw some data against it than it is to create the equivalent Java program. You can also use python to hit against command line programs, generate a ton of garbage (but still valid) test data, etc.. quite easily.

The other thing that dynamic languages are big on is code generation. Creating the C#/C++/Java code. Some examples follow:

The first code generation task I often see is people using dynamic languages to maintain constants in the system. Instead of hand coding a bunch of enums, a dynamic language can be used to fairly easily parse a text file and create the Java/C# code with the enums.

SQL is a whole other ball game but often you get better performance by cut and pasting 100 times instead of trying to do a function (due to caching of execution plans or putting complicated logic in a function causing you to go row by row instead of in a set). In fact it is quite useful to use the table definition to create certain stored procedures automatically.

It is always better to get buy in for a code generator. But even if you don't, is it more fun to spend time cutting/pasting or is it more fun to create a Perl/Python/Ruby script once and then have that generate the code? If it takes you hours to hand code something but less time to create a code generator, then even if you use it once you have saved time and hence money. If it takes you longer to create a code generator than it takes to hand code once but you know you will have to update the code more than once, it may still make sense. If it takes you 2 hours to hand code, 4 hours to do the generator but you know you'll have to hand code equivalent work another 5 or 6 times than it is obviously better to create the generator.

Also some things are easier with dynamic languages than Java/C#/C/C++. In particular regular expressions come to mind. If you start using regular expressions in Perl and realize their value, you may suddenly start making use of the Java regular expression library if you haven't before. If you have then there may be something else.

I will leave you with one last example of a task that would have been great for a dynamic language. My work mate had to take a directory full of files and burn them to various cd's for various customers. There were a few customers but a lot of files and you had to look in them to see what they were. He did this task by hand....A Java/C# program would have saved time, but for one time and with all the development overhead it isn't worth it. However slapping something together in Perl/Python/Ruby probably would have been worth it. He spent several hours doing it. It would have taken less than one to create the Python script to inspect each file, match which customer it goes to, and then move the file to the appropriate place.....Again, not part of the standard job. But the task came up as a one off. Is it better to do it yourself, spend the larger amount of time to make Java/C# do the task, or spend a much smaller amount of time doing it in Python/Perl/Ruby. If you are using C or C++ the point is even more dramatic due to the extra concerns of programming in C or C++ (pointers, no array bounds checking, etc.).

Why learn Perl, Python, Ruby if the company is using C++, C# or Java as the application language?

A lot of times some quick task comes up that isn't part of the main software you are developing. Sometimes the task is one off ie compare this file to the database and let me know the differences. It is a lot easier to do text parsing in Perl/Ruby/Python than it is in Java or C# (partially because it is a lot easier to use regular expressions). It will probably take a lot less time to parse the text file using Perl/Ruby/Python (or maybe even vbscript cringe and then load it into the database than it would to create a Java/C# program to do it or to do it by hand.

Also, due to the ease at which most of the dynamic languages parse text, they are great for code generation. Sure your final project must be in C#/Java/Transact SQL but instead of cutting and pasting 100 times, finding errors, and cutting and pasting another 100 times it is often (but not always) easier just to use a code generator.

A recent example at work is we needed to get data from one accounting system into our accounting system. The system has an import format, but the old system had a completely different format (fixed width although some things had to be matched). The task is not to create a program to migrate the data over and over again. It is to shove the data into our system and then maintain it there going forward. So even though we are a C# and SQL Server shop, I used Python to convert the data into the format that could be imported by our application. Ultimately it doesn't matter that I used python, it matters that the data is in the system. My boss was pretty impressed.

Where I often see the dynamic languages used for is testing. It is much easier to create a Python/Perl/Ruby program to link to a web service and throw some data against it than it is to create the equivalent Java program. You can also use python to hit against command line programs, generate a ton of garbage (but still valid) test data, etc.. quite easily.

The other thing that dynamic languages are big on is code generation. Creating the C#/C++/Java code. Some examples follow:

The first code generation task I often see is people using dynamic languages to maintain constants in the system. Instead of hand coding a bunch of enums, a dynamic language can be used to fairly easily parse a text file and create the Java/C# code with the enums.

SQL is a whole other ball game but often you get better performance by cut and pasting 100 times instead of trying to do a function (due to caching of execution plans or putting complicated logic in a function causing you to go row by row instead of in a set). In fact it is quite useful to use the table definition to create certain stored procedures automatically.

It is always better to get buy in for a code generator. But even if you don't, is it more fun to spend time cutting/pasting or is it more fun to create a Perl/Python/Ruby script once and then have that generate the code? If it takes you hours to hand code something but less time to create a code generator, then even if you use it once you have saved time and hence money. If it takes you longer to create a code generator than it takes to hand code once but you know you will have to update the code more than once, it may still make sense. If it takes you 2 hours to hand code, 4 hours to do the generator but you know you'll have to hand code equivalent work another 5 or 6 times than it is obviously better to create the generator.

Also some things are easier with dynamic languages than Java/C#/C/C++. In particular regular expressions come to mind. If you start using regular expressions in Perl and realize their value, you may suddenly start making use of the Java regular expression library if you haven't before. If you have then there may be something else.

I will leave you with one last example of a task that would have been great for a dynamic language. My work mate had to take a directory full of files and burn them to various cd's for various customers. There were a few customers but a lot of files and you had to look in them to see what they were. He did this task by hand....A Java/C# program would have saved time, but for one time and with all the development overhead it isn't worth it. However slapping something together in Perl/Python/Ruby probably would have been worth it. He spent several hours doing it. It would have taken less than one to create the Python script to inspect each file, match which customer it goes to, and then move the file to the appropriate place.....Again, not part of the standard job. But the task came up as a one off. Is it better to do it yourself, spend the larger amount of time to make Java/C# do the task, or spend a much smaller amount of time doing it in Python/Perl/Ruby. If you are using C or C++ the point is even more dramatic due to the extra concerns of programming in C or C++ (pointers, no array bounds checking, etc.).

Which programming language suits web critical application development?

The page you are linking only tells half the truth. Of course native languages are faster than dynamic ones, but this is critical to applications with high computing requirements. For most web applications this is not so important. A web request is usually served fast. It is more important to have an efficient framework, that manages resources properly and starts new threads to serve requests quickly. Also the timing behaviour is not the only critical aspect. Reliable and error-free applications are probably better achieved with dynamic languages.

And no, faster hardware isn't a solution. In fact Google is famous for using a cluster of inexpensive machines.

Real and non-embedded use of Ruby, Python and their friends

Python (combined with PyQt) is a very solid combination for GUI desktop applications (note that while QT is LGPL, PyQt (the Python bindings) is dual licensed: GPL or commercial).

It offers the same (GUI library-wise) as Qt on C++ but with Python's specific strenghts. I'll list some of the more obvious ones:

  • rapid prototyping
  • extremely readable (hence maintainable) code

Should I stick with C(++) for desktop apps?

In general: no, unless you want to / need to (for a specific reason).

Is there anything that java cannot do? But other's can?

All general purpose programming languages in use are Turing complete, so in that very rigorous theoretical sense, they have the same power. There's NOTHING that is computable in, say, C#, but not computable in Java.

In a more practical point of view, though, yes, there are things that other languages can do that Java can't. It really depends on how you want to pick your nits. Java has no 8-bit unsigned byte, Java can't convert an int to a boolean value, Java has no first class methods, Java has no pass by reference semantics, etc. None of those would prevent you from getting things done, but they are nonetheless things that Java can't do that other languages can.

As far as learning how to program goes, Java is not a bad choice. It's practical enough, but can be quite verbose. Rather subjectively, though, there are other more "fun" languages for learning that is just as if not more instructive than Java.

With regards to this remark:

I've been doing java programming for many years and I sometimes have the feeling that I wouldn't need to learn another one.

I'm sorry to say that this is a very self-limiting point of view. Learning another language can really expand your mind on what programming is all about. It can also be fun.

Related questions

  • Is it better to master a few programming languages than to learn many?
  • Why learn Perl, Python, Ruby if the company is using C++, C# or Java as the application language?
  • Why you/I should not learn another language?
  • The benefits of learning languages that you won’t use
  • Which programming languages have helped you to understand programming better?
  • Learning multiple languages
  • Which is more advantageous: Learning new languages or increasing knowledge of ones you already know?

Should I learn Python after C++?

There's no right or wrong answer, really. But I think you'll benefit more from learning Python. Given the similarities between C# and C++, you'll learn a different way of thinking from Python. The more ways you learn to think about a problem, the better it makes you as a programmer, regardless of the language.

Study Objective-C , Ruby OR Python?

I use all the languages C++, Ruby, Python and Objective-C. I like each one in different ways. If you want to get into Mac and iPhone development as others I recommend Objective-C.

One of the benefits not mentioned is that Objective-C is a proper superset of C (C++ is almost a superset), that means you can bring over all your C programming knowledge from doing C++ to Objective-C programming. In fact you can also mix in C++ code in Objective-C code.

You can't do that in a seamless way in Python and Ruby. The reason why you can do this is that Objective-C is actually a very simple language.

Originally it was just C with a custom made preprocessor which took statements like this:

[rectangle setX: 10 y: 10 width: 20 height: 20];

and converted it to this before compiling:

  objc_msgSend(rectangle, "setX:y:width:height:", 10, 10, 20, 20);

Apart from that Ruby, Python and Objective-C are very similar in their object model at least compared to C++. In C++ classes are created at compile time. In Objective-C, Ruby and Python classes are things created at runtime.

I wrote some stuff on why Obj-C is cool here

String formatting vs String Interpolation

String formatting is a rather general term of generating string content from data using some parameters. For example, creating date strings from date objects for a specific date format, number strings from numbers with a particular number of decimal digits or a number of leading spaces and zeroes etc. It can also involve templates, like in sprintf function present in C or many other languages, or e.g. str.format in Python. For example, in Ruby:

sprintf("%06.2f", 1.2) # float, length 6, 2 decimals, leading zeroes if needed
# => "001.20"

String interpolation is a much more restricted concept: evaluating expressions embedded inside string literals and replacing them with the result of such evaluation. For example, in Ruby:

"Two plus two is #{2+2}"
# => "Two plus two is 4"

Some languages can perform formatting inside interpolation. For example, in Python:

f"Six divided by five is {6/5:06.2f}"
# => "Six divided by five is 001.20"

The concepts are language-agnostic. However, it is not guaranteed that all programming languages will have a built-in capability for one or both of them. For example, C has no string interpolation, but it has string formatting, using the printf family of functions; and until somewhat recently, JavaScript did not have either, and any formatting was done in a low-tech way, using concatenation and substringing.



Related Topics



Leave a reply



Submit