5 things to sort out as a multi-lingual software engineer

Photo by Pixabay on Pexels.com

Writing code and building software is fun no matter which language one uses. But what we have found is that there is no “language to rule them all”. There are a number of languages out there each with its own quirks, strengths and weaknesses and that’s just amazing.

So where does that leave us as software engineers? We will probably need to pick up more than one languages as we go along, but what’s the best way to go about that?

Continue reading “5 things to sort out as a multi-lingual software engineer”

Variable scopes and shadowing in Go

Photo by Eneida Nieves on Pexels.com

A lot of things in life are a matter of perspective and visibility and the same applies to variables in Go 😅. But what is a variable’s scope, how is it defined and what does it mean to shadow a variable in Go?

Let’s (very) loosely say that the scope of a variable declares where this variable is visible from ie. if we have declared a variable at the top of the file then it’s visible from within the entire code of that file.

We can go even deeper than that though and we can break this question down into Go specific terms.

Continue reading “Variable scopes and shadowing in Go”

Sorting in Go using Bubble sort

Go has its own package for handing sorting – called “sort” but in this post we are going to use the Go language to implement a sorting algorithm called Bubble sort.

Problem definition: Given a slice of integers sort them in ascending order

Bubble sort is an iterative comparison algorithm that sorts the elements by swapping them around if they are out of order. If a larger element comes before a smaller one => swap them and move on to the next position of the array.

Continue reading “Sorting in Go using Bubble sort”

String manipulation in Go

I find the way that strings have been implemented in Go to be really interesting but also a bit confusing when you are first introduced to them. Go has native UTF8 support, which flows through how the source code is written to how strings and “runes” are represented (runes is the thing that really got me by surprise but more on that later). So what does Go do differently with strings that is worth mentioning?

Continue reading “String manipulation in Go”

JQuery textarea text limit counter

This is slightly different implementation of the jquery textarea text limit counter found at: http://www.scriptiny.com/2012/09/jquery-input-textarea-limiter/. The main difference is that the user is not cutoff when he reaches the limit of the allowed characters but he is notified via the counter that his text is longer than expected.

The idea behind it is to have a textarea that accepts user input and there is  a limit in the characters that you want you are allowed to type in the textarea. While you type in characters in the textarea a counter is updated that shows the remaining characters. The number is correct even when you reload the page and the area is pre-populated with text. This particular demo uses jquery 1.5.1

Continue reading “JQuery textarea text limit counter”

PHP: The Scope Resolution Operator (::)

In PHP the Scope Resolution Operator (which is actually the double colon or Paamayim Nekudotayim as it is its official name) has many uses. From the PHP manual pages (Manual) I quote

The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class. When referencing these items from outside the class definition, use the name of the class.

So, I recently decided to go ahead and test this operator in a bit more detail and discovered something I did not know about the way PHP decides to give you access to its public methods.
Let us consider the following php class

Continue reading “PHP: The Scope Resolution Operator (::)”

How to add Captcha verification in the comments of the Yii blog demo

This post is about adding captcha verification in the comments section of the Yii demo blog. This post was triggered from two comments posted on the page of the tutorial (Comment 1 and Comment 2). In order for you to follow through the current post you need to have the Yii framework in place and you need to have followed all the steps of the Blog Tutorial up untill the “Creating and Displaying Comments” section. So, let’s start:

If you have followed the tutorial you should by now have a working Leave a comment form in place that is displayed underneath each individual post of your blog web application. The form should contain the Name, Email, Website and Comment fields that will populate the corresponding properties of your Comment model. The Post ID should be set on submit, the Status of the Comment should also be set on submit and the Time Created should be set just before saving the Comment (if this is a newly created comment).

Continue reading “How to add Captcha verification in the comments of the Yii blog demo”

How to get your Error reporting constant values

PHP lets you specify the Error Reporting level, so that when a piece of your code is run based on this setting of the php.ini file the generated errors and/or warnings will be shown or not. Generally speaking in a development environment it is recommended to set this as high as possible so that you are informed about all the little details of your code whereas in  a production environment this setting is usually set to something less “explanatory”.

In order to set the value of the error_reporting directive php constant values and bitwise operators are used, as they are described in the PHP manual . The setting can be set during runtime using the php error_reporting() function (manual) passing as a parameter the int value calculated based on the constant values and bitwise operators used. The function returns the integer value of the previous error_reporting level.

Now if you wish to find out what is your current error_reporting level you could go and have a look in your php.ini file or you could use the error_reporting() function with no parameters, in which case the function will return an integer value representing the current error reporting level. If you go via the php.ini file you will see the names of the constants used and the operations applied to produce your current reporting level but if you try to get a similar result via a php file that you have written you might notice that it is more difficult to understand  what is going on since now you are only dealing with an integer value and not with the named constants. So which is the description of your error reporting level and how can you retrieve it from within a php file?

Continue reading “How to get your Error reporting constant values”