Programming Languages war
Python, PHP, Javascript (Nodejs)
Mother's day

Programming Languages war Python, PHP, Javascript (Nodejs) Mother's day

Carlos Rivas's photo
Carlos Rivas

Published on May 10, 2021

7 min read

Hey my friends, a new post about this war. I don't know which is better, but I'll try to figure it out. I hope y'all enjoy this series. Here we go!

Today I'm going to give you a good gift for your moms, I don't know when Mother's Day is in your countries, but here in Venezuela is the second Sunday in May, I'm going to make a random code to give you phrases for your mother, so when not have nothing to say just run the code or if your mother or you are a mother and a developer, it is a good gift. 😅

Python

First import randint from random, add all phrases that you want to tell your mother, the method randint needs two values, from and to, and return the phrase.

from random import randint


class MomsDay:
  phrases = [
      'A mother is your first friend, your best friend, your forever friend.',
      'When you are looking at your mother, you are looking at the purest love you will ever know.',
      'Mother is the heartbeat in the home; and without her, there seems to be no heartthrob.',
      'Mothers are like glue. Even when you can’t see them, they’re still holding the family together.',
      'My Mother: She is beautiful, softened at the edges and tempered with a spine of steel. I want to grow old and be like her.',
      'Mother is the name for God in the lips and hearts of little children.',
      'The influence of a mother in the lives of her children is beyond calculation.',
      'It may be possible to gild pure gold, but who can make his mother more beautiful?',
      'There is no role in life that is more essential than that of motherhood.',
      'Youth fades; love droops; the leaves of friendship fall; A mother’s secret hope outlives them all.',
      'Motherhood is the exquisite inconvenience of being another person’s everything.',
      'Only mothers can think of the future because they give birth to it in their children.',
      'My mother was my role model before I even knew what that word was.',
      'To describe my mother would be to write about a hurricane in its perfect power.',
      'My mother is a walking miracle.',
      'A mother understands what a child does not say.',
      'The world needs our mothers.',
      'A mother’s hug lasts long after she lets go.',
      'There is nothing as sincere as a mother’s kiss.',
      'Life began with waking up and loving my mother’s face.',
      'A mother is always the beginning. She is how things begin.',
      'We are born of love; love is our mother.',
      'Mother: the most beautiful word on the lips of mankind.',
      'There is no influence so powerful as that of the mother.',
      'A mother’s arms are more comforting than anyone else’s.',
      'All that I am, or ever hope to be, I owe to my angel mother.',
      'A mother is the one who fills your heart in the first place.',
      'Mother is one to whom you hurry when you are troubled.',
      'A mother’s love is more beautiful than any fresh flower.'
  ]

  def getPhrase(self):
    num = randint(0, len(self.phrases) - 1)
    return self.phrases[num]


mom = MomsDay()
print(mom.getPhrase())

PHP

Add all phrases that you want to tell your mother, the method random_int need two values, from and to, and return the phrase.

<?php
class MomsDay
{

    private $phrases = [
        'A mother is your first friend, your best friend, your forever friend.',
        'When you are looking at your mother, you are looking at the purest love you will ever know.',
        'Mother is the heartbeat in the home; and without her, there seems to be no heartthrob.',
        'Mothers are like glue. Even when you can’t see them, they’re still holding the family together.',
        'My Mother: She is beautiful, softened at the edges and tempered with a spine of steel. I want to grow old and be like her.',
        'Mother is the name for God in the lips and hearts of little children.',
        'The influence of a mother in the lives of her children is beyond calculation.',
        'It may be possible to gild pure gold, but who can make his mother more beautiful?',
        'There is no role in life that is more essential than that of motherhood.',
        'Youth fades; love droops; the leaves of friendship fall; A mother’s secret hope outlives them all.',
        'Motherhood is the exquisite inconvenience of being another person’s everything.',
        'Only mothers can think of the future because they give birth to it in their children.',
        'My mother was my role model before I even knew what that word was.',
        'To describe my mother would be to write about a hurricane in its perfect power.',
        'My mother is a walking miracle.',
        'A mother understands what a child does not say.',
        'The world needs our mothers.',
        'A mother’s hug lasts long after she lets go.',
        'There is nothing as sincere as a mother’s kiss.',
        'Life began with waking up and loving my mother’s face.',
        'A mother is always the beginning. She is how things begin.',
        'We are born of love; love is our mother.',
        'Mother: the most beautiful word on the lips of mankind.',
        'There is no influence so powerful as that of the mother.',
        'A mother’s arms are more comforting than anyone else’s.',
        'All that I am, or ever hope to be, I owe to my angel mother.',
        'A mother is the one who fills your heart in the first place.',
        'Mother is one to whom you hurry when you are troubled.',
        'A mother’s love is more beautiful than any fresh flower.',
    ];

    public function getPhrase()
    {
        $num = random_int(0, count($this->phrases) - 1);
        return $this->phrases[$num];
    }
}

$mom = new MomsDay();
var_dump($mom->getPhrase());
?>

Javascript

Add all phrases that you want to tell your mother, the method Math.floor to get an integer, the method Math.random() gets a value between 0 and 1 and you have to multiply by phrases length and return the phrase.

class MomsDay {
  phrases = [
    'A mother is your first friend, your best friend, your forever friend.',
    'When you are looking at your mother, you are looking at the purest love you will ever know.',
    'Mother is the heartbeat in the home; and without her, there seems to be no heartthrob.',
    'Mothers are like glue. Even when you can’t see them, they’re still holding the family together.',
    'My Mother: She is beautiful, softened at the edges and tempered with a spine of steel. I want to grow old and be like her.',
    'Mother is the name for God in the lips and hearts of little children.',
    'The influence of a mother in the lives of her children is beyond calculation.',
    'It may be possible to gild pure gold, but who can make his mother more beautiful?',
    'There is no role in life that is more essential than that of motherhood.',
    'Youth fades; love droops; the leaves of friendship fall; A mother’s secret hope outlives them all.',
    'Motherhood is the exquisite inconvenience of being another person’s everything.',
    'Only mothers can think of the future because they give birth to it in their children.',
    'My mother was my role model before I even knew what that word was.',
    'To describe my mother would be to write about a hurricane in its perfect power.',
    'My mother is a walking miracle.',
    'A mother understands what a child does not say.',
    'The world needs our mothers.',
    'A mother’s hug lasts long after she lets go.',
    'There is nothing as sincere as a mother’s kiss.',
    'Life began with waking up and loving my mother’s face.',
    'A mother is always the beginning. She is how things begin.',
    'We are born of love; love is our mother.',
    'Mother: the most beautiful word on the lips of mankind.',
    'There is no influence so powerful as that of the mother.',
    'A mother’s arms are more comforting than anyone else’s.',
    'All that I am, or ever hope to be, I owe to my angel mother.',
    'A mother is the one who fills your heart in the first place.',
    'Mother is one to whom you hurry when you are troubled.',
    'A mother’s love is more beautiful than any fresh flower.'
  ];

  getPhrase() {
    const num = Math.floor(Math.random() * this.phrases.length);
    return this.phrases[num];
  }
}

const mom = new MomsDay();
console.log(mom.getPhrase());

Conclusion

  • Structure: Each language has a little difference.
  • Lines: Python: 43, PHP: 46, Javascript: 41
  • Time to execution: Python: 13 ms, PHP: 16 ms, Javascript: 23 ms

I hope that your mothers have a great day or if you are a mother happy day!

I hope you enjoy my post and remember that I am just a Dev like you!

 
Share this