Cheers to WordPress

I have probably said it before but will say again … WordPress is great. I spend most of my day writing and reviewing code at work and is nice to be able to write in words for a change. 

Word press is built with PHP – I know PHP has it's critics and sure there is a lot of hacked together PHP scripts out there but I am sure there are is a lot of good code also. WordPress is it's real success story (sorry not a facebooker) in my opinion.

In the past I have dug into the code base and found it a little hairy (used to OOP) – this was years ago though. I don't know what it looks like now, and whatever about the code base the ui seems to be orgainzed very well.

WordPress is just so flexible and straight forward and is great fun. Not sure about using it for businesses to be honest – have been there before and I think eventually you out grow it. Small businesses should be fine!

C# and NodeJs – a brief comparison

In the past these two had very little in common, however I thought I’d briefly compare as they are increasingly used together and becoming quite similar in places.

JavaScript is said to be a functional programming language with object oriented aspects and c# is the reverse really.

C# is compiled – modern JavaScript is compiled in a sense but not to the same degree.

C# was designed and implementation in a thoughtful and considered way – it is said JavaScript was built in 10 days (which is actually impressive if true). This is clear throughout the structure of the languages. Although JavaScript is very fluid – it has a lot of curious behaviours – equality statements as an example.

One of the biggest differences in the two is that c# relies on threading to support concurrency whereas node js does not, although threads are used under the hood.

They are quite different but increasingly more a like. Async await was first in C# but now also JavaScript. 

Classes are now also supported in JavaScript but not interfaces. Typescript is an option for those who want to go further in this direction.

C# has also adopted implicit typing with the use of “var”. And JavaScript as evolved by adding const and let. In C# you would add modifiers to make a variable a constant.

One of the biggest challenges I encountered recently was with array / collection mapping and filtering. Linq is the way to do it in C# whereas js gives you a few different options – lodash is what is used in my place of work. They are similar but a little different. I won’t go into detail here.

There are many more similarities and differences these are but a few….

 

Node Js

 

a departure from what is normal, usual, or expected, typically an unwelcome one

Aberration 

This is not meant be an insult or even a critism but more just a statement of how it probably is. It’s also not necessarily a bad thing although the use of the word aberration usually is as the the second part of the citation above states.

Node started off as a neat attempt at solving concurrency problems. Mainly, I think, due to the popularity of JavaScript and ease of adoption, it has snow-balled and in London at least, it seems node skills are very much in demand.

Ryan Dahl himself has said that he left Node behind as he felt that golang provided a better solution the issue of concurreny: https://medium.com/@imior/10-things-i-regret-about-node-js-ryan-dahl-2ba71ff6b4dc

Perhaps if he stayed in charge of the languages development things would be different but I'm not sure if that would be for better or worse. From what I understand Ryan was for callbacks and against promises. I think he has since changed his stance but from what I read, there are still a minority of node developers who believe node should be callbacks alone and if you organize your code correctly callbacks are easy to read – perhaps they are right.

Both callbacks and promises seem very unintuitive to those not used to them and fit with the term abberation in that you need to think differently to the previously traditional ways of doing things. I have been happy to adopt async await as I am pretty comfortable with that from C# at this stage.

It is probably fair to say that Node and JavaScript don't represent the safest way of programming though. Dependencies seem chaotic at times. Package lock was introduced to make things better but is it's own special brand of chaos. Many of the packages up there seem to be well intentioned but maybe lacking in let's say 'polish'.

I think Node has helped a lot of people to get started with programming as it is so easy to get going. Issues are being ironed out as I speak.

JavaScript is the language of the browser so designers and people with a little coding experience are able to get more easily involved. In many cases the role of designer and developer have probably merged and I think JavaScript is partially responsible for this fushion of skills, although languages like PHP existed before and arguably have the same properties in terms of ease of use and learnability.

This is good and bad. There is more code but the code is not always better, and the problems tend to come further down the road. The point is though, Node and JavaScript have influenced the industry a lot. As well as getting more people involved, it has probably influenced the way other languages have developed, see C# and NodeJs – a brief comparison.

I’ve been programming with Node for 5 or 6 years (on and off) now and Javascript longer and I appreciate some of its advantages but I also see and understand a lot of the issues it creates.

 

 

Problems with permalinks in WordPress on Ubuntu

I’ve had problems with permalinks in the past on Ubuntu and always forget one thing or other so here is a set of instructions on setting up those pesky permalinks. This is what I have done in past but if you can think of anything else, please let me know.

1. Create a new “.htaccess” file in your root WordPress directory.

2. Enabling mod_write in the Apache2 server. Type:
sudo a2enmod rewrite

3. Open a terminal and type:
sudo chown -v :www-data “//.htaccess”

4. Also give write access to the file:
sudo chmod -v 664 “//.htaccess”

5. Restart the Apache:
sudo /etc/init.d/apache2 restart
We are all done with the command line prompt; you can close the command line window now.

5. Go into your WordPress admin screen. Click on settings, then on permalinks and select whichever permalink layout you wish. Hit Save button.

Master pages in PHP

One of the good things about  .NET is that you can you use master pages. A master page is basically a template page which you can use to control the layout of other pages. Its usefull to ensure consistency across all pages on a site and most importantly it cuts down on a lot of repetitive programming.

PHP does not support such a feature but its easy enough to achieve the same effect. The way I do this is by creating a PHP page called master.php. I fill out the HTML parts as normal and in the place which I want to have varying content between pages, I add PHP variables.

When implementing the inheriting pages later I define the same variables but also assign content to them. After the variables have been assigned content html, I import my master.php page.  Nice.

Here is an example:

The master page, Master.php

<html>

<head>..</head>

<body>….

<div id=”middle”>
<div id=”middleLeft”><?php echo $text; ?></div>
</div>

</body>

</html>

An a content page, about.php:

<?php ….

$text = “This is a good example”

include(“master.php”); ?>