Programming/Coding, Science

PHP 7: Scalar Type Declarations

One of the reason why PHP7 is actually a wall breaker of old PHP that leads to no more an ‘insane’ programming language for web development. Sure, the backward compatibilities and the baggage it brings are still there, but we need to understand that every language sucks for supports backward compatibilities.

It causes the designers/developers/community of the programming language generally enforce innovations much slower compared to others that are in their infancy or adoption phase. However, we cannot deny that backward compatibilities are also important for code reuse and that saves a lot of time and cost.

Old code works, so why reinvent the wheel? Anyway, what does this scalar type relates to backward compatibilities? Nothing, but it relates to the ecosystem of the PHP . Instead of redesign the whole language, the developers introduces several features for PHP 7that help the developers on programming a better quality with stricter typing features.

For anybody that tried Perl 6 and Golang gradual typing or Python’s type hints with mypy code analysis tool, you’ll find that PHP is not left behind as what the others has said about the language that they’ll probably use around last 14 years ago.

Advertisements
Programming/Coding

Which programming language to use when solving a problem in specific domain?

Perl


Unix/Linux scripting, system administration, one liners and command line utilities.

Python


Science, mathematics, machine learning, Raspberry Pi, web development, desktop applications, and command line utilities.

PHP


Simple to medium-sized and agile web development.

Bash


Bourne shell replacement, simple unix scripting, and used when no better language implementations available.

Clojure


Exploratory programming and practical JVM language.

Programming/Coding

How to make commenting code fun?

Comment, comment comment. It must been a hell of a side job as a programmer or similar to do. We are programmers, we writes code, not documents, yada yada..

Well, that is what I thought in the first place.

WRONG!

Commenting is very very important in a long term or growing project. No matter how beautiful and readable your ‘self-documenting code’ will be. Why? The key is again, why?

Your code already does what it does, tell the computer to do things, and tell you what it does. However, why the code is even there in the first place? Why?

The first step to make documenting and reading it as a fun thing is, make it tell you why the code is there.

For instance, you have a function that writes to a configuration file on a Linux hosting server with only FTP access without SSH (I know it sucks, consider alternatives including DigitalOcean for VPS-like hosting or Bluehost also Dreamhost for SSH access).

An example comment for this scenario is – the server doesn’t have SSH access to execute Linux commands, so we implement this to write the code invoked from the execution of the web app.

And there ladies and gentleman, will make your life easier by commenting why instead of what.

Don’t repeat the code, assume the audience already understand the language and algorithm, and it is their fault for not taking enough time and effort to understand it (unless you writing clever code and cryptic algorithms, you are to blame instead).

Other keys like enforcing the use of good grammar and simplicity of the commenting language is also important too, but don’t let that stopping you from commenting your code if you are not fluent at the target language.

You are an awesome person for reading this. Why? because you have the passion to look the answer, to be a better developer, thus making your life and others easier to make reading codes and documentations an enjoyable experience.

Protect it, live it, love it, soon it is nothing for you, but a good habit.

Perl, Perl 5, Programming/Coding, Science

DevOps in Perl? Consider Rex.

Rex is a ‘Deployment & Configuration Management’ also knows as DevOps framework. Interestingly, it is in Perl, for Perl language. There is Ruby’s Chef & Puppet, Python’s Ansible, and Perl also has those frameworks too, but here I’m pointing to Rex because it will be much more familiar to Puppet, Chef and Ansible users in syntax and workflow perspectives.

Why do this in Perl?

Perl itself has been designed and well known for its powerful features on sysadmin tasks. Combine with this kind of framework, you are just gonna be much happier on getting the job done. Fortunately, if you are trying to opt to write ‘maintainable and long-term modules/scripts’ without using Rex, Modern Perl as a guideline should help you doing so, and CPAN with much lesser code in general.