Use what you know

Story: Save development time and effort with RubyTotal Replies: 9
Author Content
dotmatrix

Apr 07, 2016
9:26 AM EDT
I'm a little ill today... and probably a little grumpy.

However, the best advice anyone can give a coder for a particular problem is:

Use what you know

"Save time and program in xyz instead of abc language" is akin to saying: "Save time by speaking in Spanish rather than American English"

Of course, if what you know is assembly language -- then you may have a bit of a problem. ... get it? a bit...

Oh sorry, the illness is messing with me.
penguinist

Apr 07, 2016
10:43 AM EDT
First let me say that dotmatrix is spot on with the advice to use what you know. That makes total sense.

That said, I wanted to add my thoughts about Ruby as a system language. I've been using a variety of languages for scripting, bash, python, php-cli, but Ruby has impressed me a lot as a scripting language. Its "everything is an object" foundation results in some really nice advantages. All objects provide methods and all methods return objects. So with this, you can practically implement a complete algorithm in a single powerful line of code.

For example if you wanted to get the first story headline from the LXer newswire, you could do this:

require 'open-uri'

puts(open("http://lxer.com ").read.match(/(.*)storyheadline">(.*?)</)[2])

Lets look at what this powerful line of code does, piece by piece.

puts -- prints a string. What follows inside its argument evaluates to the string we want to print.

open("http://lxer.com ") -- opens a web page just like we would open a local file, its return value is a file_handle.

read -- we now read the complete "file" and return the LXer home page as a string object.

match -- since we now have a string object, we can search it with a regular expression and return a match object.

[2] -- we select our desired entry out of the match object returning the string that we want puts to display.

So if any LXers would like to see Ruby in action, here is a quickstart using the above example:

dnf install ruby
  or
apt-get install ruby

then ruby -e 'require "open-uri";puts(open("http://lxer.com ").read.match(/(.*)storyheadline">(.*?)</)[2])'


After you run that ruby snippet, you should see the first headline currently on the LXer newswire. Something like:

Save development time and effort with Ruby
dotmatrix

Apr 07, 2016
11:05 AM EDT
I'm not interested in starting a language flame war...

However, the precise same operations can be performed using a bash script and curl, grep, echo...

or

A C program using various libraries...

or

An Ada program with a high level of error handling assurance.

or even

An assembly program with only about 10,000 lines of carefully crafted op code.

The point is: Is there really a difference between typing 3 lines of code and typing 7 lines of code. I don't know the Ruby language, what you've typed makes sense to me only with an explanation -- otherwise it's just confusing. If someone doesn't know Ruby, but does know Python -- how could typing something in Ruby save any time at all. There is a prerequisite to learn what you are using.

That's why I say:

Forget all the advice about 'which programming language is best' ... use what you know or what is required by the project leader. If these two things are not the same thing, then you've got to learn a new language or find new work.

As for me and Ruby:

I learned C and assembly as a teenager. And no matter which languages I try, I usually end up in C for most things.
Fettoosh

Apr 07, 2016
12:00 PM EDT
The better question would be: Which programming language is best for a programmer to be? i.e. Easy, faster to learn, most powerful, and will do the job at hand.

JaseP

Apr 07, 2016
12:13 PM EDT
Most programming languages borrow and/or build on C syntax. That said, C is pretty low level (for a "high level" language), making some of those other languages easier and sometimes a pleasure to switch to (Java, for all the abuse it takes, being a perfect example). But sometimes, the languages are just different enough to screw you up for the others (Python, I love you, but I'm looking at YOU... ).

I will say that there's an elegant beauty to Assembly,... But doing anything truly useful in it is a real pain. But it does make me wonder how any of the more advanced features in higher level languages were ever able to be derived from assembly instructions (dynamic arrays, for example).

As for learning a new language, like Ruby,... Any new language takes about 2-3 weeks for an average coder to adjust to,... But getting good?!?! Well, you just have to keep using it for that.
penguinist

Apr 07, 2016
12:17 PM EDT
It seems that I should clarify my intent.

1. I acknowledge and strongly agree with dotmatrix' point that the best language to use for a task is one that you already know.

2. I have used multiple scripting and compiled languages and I am not advocating any one of them as the "best". That is a personal choice.

3. I personally have some experience with Ruby and I thought that in the spirit of sharing and helpfulness that I would offer an easy introduction for those who might be interested in expanding their horizons a bit. That's really what community is all about. Sharing our experiences and helping each other.

Sorry if somehow I came across as being argumentative. That was certainly far from my intention.
dotmatrix

Apr 07, 2016
12:59 PM EDT
>Sorry if somehow I came across as being argumentative. That was certainly far from my intention.

I'm argumentative today.... Sorry for that...

I suppose many of these programming languages questions seem to come down to how many layers of abstraction are acceptable.

In languages like Ruby, Python, and tcl/tk the high level of abstraction allows for portability and maintainability of code. However, there can also be much confusion regarding the abstraction itself and which library to use to obtain the desired result.

With Ruby, there are 'gems'... and then everything just goes to hell... I can search the interwebs for examples of how to do 'jkl' task with Ruby and get about 10 different possible pathways. Each of these pathways may require a different set of gems downloaded from a different part of the Internet... And most of the 'gems' that are included in a given GNU/Linux distro are either outdated or no longer used by many programmers.

So... with Ruby - like node.js - there is a requirement to relearn how to find libraries that do things...

This xkcd comes to mind:

https://xkcd.com/1654/

Anyway --- I should stop posting, because I feel terrible and should rest... and when I feel terrible, I get argumentative.
nmset

Apr 07, 2016
1:03 PM EDT
Using a language that's not company owned is definitely a criteria of choice in my view. Look at the mess around Android right now. I'm sure Google regrets that choice .
Heather

Apr 07, 2016
1:12 PM EDT
I liked the xkcd. That list seems fairly complete. Thanks for passing it along.

Regarding uptodate gems, my personal philosophy is to get libraries from the "upstream" repo rather than relying on the distribution (since the distros are seldom uptodate). So for python libraries I do

pip install <library>

and for ruby libraries I do

gem install <library>



gary_newell

Apr 14, 2016
5:29 PM EDT
By definition most programming and scripting languages have the same basic constructs. They all have variables, loops, arrays, conditions etc. The rest is just syntax really.

I prefer a language that is easier to read by the naked eye such as C#, VB.NET, Java etc. After 20 years of programming I have found that people have become obsessed with evangelising about programming. You must use test driven development. You must know this design pattern or that design pattern. Do you know how to use MVC? No you don't use that anymore, you use MVVM etc.

In one way it gets easier to be a programmer every year because whatever you are trying to do usually has been done before and there are loads of third party libraries that you can use. On the other hand it is getting harder because you have to learn the latest buzz terms.

I mainly develop for Windows and in the past few years with .NET we have switched from Winforms to WPF and on the web side it has changed from Web Forms to MVC and Entity Framework. Test driven development has really kicked in and project managers hear about this and try and revert a huge application with thousands of lines of code to use TDD which is much harder to do after the event than if you started off in that fashion. Then there are constructor factories, inversion of control, javascript libraries such as JQuery etc.

I decided a while ago to concentrate on the database side and I am glad I did. Nothing lasts more than a year on the development side without somebody stating something else as the next big thing.

Database developers are in good demand and I am thankful I took the time to learn ETL tools such as SSIS and reporting tools such as SSRS. Thankfully SQL doesn't really change all that much either.

Posting in this forum is limited to members of the group: [ForumMods, SITEADMINS, MEMBERS.]

Becoming a member of LXer is easy and free. Join Us!