Tuesday, September 12, 2017

Ruby is not perfect

Programmers seem to have, in most cases, an almost 'religious' opinion about the programming languages they use. For many years I've been talking about this and saying this is not only ridiculous, but also dangerous.

When one have this kind of position, defending something beyond rationality, it is difficult to improve this something. No criticism, no change.

I love Ruby. In many senses it is the best programming language I've ever used. And god knows I used many of them in the last 33, since I learned FORTRAN back in 1984.

But Ruby is not perfect. As all other languages, it has its share of bullshit and this post is to talk about one of them.

If you visit this blog here you'll find this strange explanation


So, in Ruby we have 'mutable constants'. And I ask what is the meaning of calling something 'a constant' if you may change its value anytime you want. I don't know exactly what was in Matz mind when he planned this, but this is not good, this is not sensible, in my humble opinion.

And here we are. We need freeze to make a constant really constant. Ruby programmers are always talking about semantics. Now, what could be less semantic than this?

I'm not telling you I'll give up Ruby for the sake of this crazy detail. I'm not telling you that it is a bad programming language. Ruby is still my favorite programming language, along with Javascript... and Java... and Perl... Well, there are lots of programming languages I love, for different reasons.

What I am telling you is... Don't be blinded by the love you feel for your programming language. When you do this, you avoid criticizing it, and this slows down its evolution.

Wednesday, August 9, 2017

Tiobe ranking of programming languages (August 2017) commented

And here I am again with my comments about Tiobe ranking of programming languages.


As me may see, Visual Basic .NET is up two positions considering August 2016. And I've been noticing some more questions about it at StackOverflow and some programming groups at Facebook. Don't know yet why is that so, but I would like to listen to some suggestions. Do you believe this is a tendency or a temporary thing?

It is not that PHP and Javascript felt. Visual Basic .NET passed them, just this. Otherwise they would be steady. But until last December Javascript was going up at fast speed. Should we consider that the large number of Javascript libraries appearing everyday are making the environment for this language to complicated?

Ruby is also up two positions, as I had told you it would happen by mid 2016. I believe this is a tendency, not a temporary thing.

Swift is up three positions and this is not surprise to me at all. It is a nice language, with a reasonable learning curve. It will grow even more in the next few months.

Delphi / Object Pascal felt one position and this is no surprise at all.

By July 2016 I was asking why Assembly was going up so fast. I though all that excitement about "Internet of Things" was making it explode. And I think I was right, because I seldom read about this expression anymore and Assembly is falling fast. Four positions since August 2016!

Where is the "Internet of Things"? Fashion comes and fashion goes. I've seen a lot of this in the last 32 years in this area.

"R" is up one position, and Matlab follows the same path up, because Data Science is the new expression in all mouths and brains. Is this a tendency? I still don't know.

Go is up four positions and it is definitely a tendency, at least for a few more years. Not a particularly suitable language to me, but remember... Google, and Google's money, is backing it!!!

Objective-C is falling down. I believe this is related with the rise of React Native and Xamarin for mobile development.

I'd like to hear from you in the comments about all this!

Decks of cards

Given and array of cards like

["9C", "KS", "AC", "AH", "8D", "4C", "KD", "JC", "7D", "9D", "2H", "7C", "3C", "7S", "5C", "6H", "TH"]

how many complete decks of cards may one extract from this array.

This problem was proposed to me and I solved it the following way
Can someone suggest a shorter and/or more efficient solution?

OBS: About the representation of the cards:

9C = 9 of Clubs
KS = King of Spades
AH = Ace of Hearts
7D = 7 of Diamonds

OBS: In the array above there are no complete decks. This array here

["2S", "2C", "2D", "2H", "3S", "3C", "3D", "3H", "4S", "4C", "4D", "4H", "5S", "5C", "5D", "5H", "6S", "6C", "6D", "6H", "7S", "7C", "7D", "7H", "8S", "8C", "8D", "8H", "9S", "9C", "9D", "9H", "TS", "TC", "TD", "TH", "JS", "JC", "JD", "JH", "QS", "QC", "QD", "QH", "KS", "KC", "KD", "KH", "AS", "AC", "AD", "AH", "2S", "2C", "2D", "2H", "3S", "3C", "3D", "3H", "4S", "4C", "4D", "4H", "5S", "5C", "5D", "5H", "6S", "6C", "6D", "6H", "7S", "7C", "7D", "7H", "8S", "8C", "8D", "8H", "9S", "9C", "9D", "9H", "TS", "TC", "TD", "TH", "JS", "JC", "JD", "JH", "QS", "QC", "QD", "QH", "KS", "KC", "KD", "KH", "AS", "AC", "AD", "AH", "2S", "2C", "2D", "2H", "3S", "3C", "3D", "3H", "4S", "4C", "4D", "4H", "5S", "5C", "5D", "5H", "6S", "6C", "6D", "6H", "7S", "7C", "7D", "7H", "8S", "8C", "8D", "8H", "9S", "9C", "9D", "9H", "TS", "TC", "TD", "TH", "JS", "JC", "JD", "JH", "QS", "QC", "QD", "QH", "KS", "KC", "KD", "KH", "AS", "AC", "AD"]

contains two complete decks of cards.

Thursday, June 22, 2017

At the libray

I was tired of programming (Yes, sometimes it happens to me!) and then decided I needed to read a bit to relax.

Libraries are like Paradise to me. Or, better saying, if there is a Paradise, and by any chance I go ther someday, it will be like a library to me.

And there I was, with my noble computer and a few books, trying to decide what would suit me better, when a few teenagers, boys and girls, sat close to me and started studying Math.

Now, if there is something that appeals to me, maybe even more than programming and books, is Math, my old passion. I've been in love with Math since my early childhood.

I was listening and trying not to interfere in their study. Young people must be allowed to make their onw discoveries. Don't meddle with them when they are doing this. Besides, they were doing pretty well. One of the boys was the leader of the pack and this reminded me of myself, 35 years ago, at National Libray in Rio the Janeiro, leading my own team and preparing to enter college with no money to pay for a prep school.

They were suddenly discussing permutations. And they had an insteresting problem related to the permutations of the Portuguese word CONQUISTA (meaning CONQUER in English).

They wanted to know, first, how many permutations this word has. Then how many of these permutations started with a vowel. Then how many would start and end with a consonant. Finally, how many of them would have the letter "C" before the letter "A".

And using Ruby I could give the answers in a few seconds, by using ths program.

Of course I haven't given them the answers. As I said above, I just don't like to interfere with young people learning. They can learn by themselves. But you may notice some interesting uses of Ruby idioms.


Sunday, June 18, 2017

Downloading eBooks with Ruby

I found an excellent resource with books about Artificial Intelligence here.

It happens that nobody wants to download these books one by one, then I decided to create a ruby script to do this.

I'm posting this here just to tell you Ruby is really a general purpose language. You may use it to many different tasks in your system.