My strategy for learning a programming language quickly

When I first arrived at my new school, I was completely unaware of what programming language they were using to teach the students – it’s something that is prone to change over time and isn’t usually mentioned on a job spec. Many schools throughout the UK will use Python from start to finish in both a procedural and object-oriented fashion later down the line, whereas some schools are still using Visual Basic. I was alarmed to find out that the senior students use C# – a language I had very little knowledge of and experience using outside of playing with it in Unity. Or so I thought.

This article is all about how I was able to rapidly learn C# and begin adding it to my programming repertoire because I was suddenly in a position where I had to! This isn’t a situation that is unique to educators such as me; as a developer, a system architect, or whatever role you are currently in or aspire to be in, there could be times where you too are forced to rapidly learn a new language, framework, or technology in the face of new circumstances, such as a new client or acquisition, or maybe your boss was just feeling malevolent.

Tip 0) A reminder that the language acquisition overlap is huge

Chances are, what you know already in another programming language will transfer over to a new one that you’re attempting to learn. Core concepts such as variables, classes, functions, arrays, and so on are more often than not going to remain identifiable as you change technology, give or take semantic differences. This is just like how once you learn how to speak another language, you get more efficient at the language learning process.

Granted, some jumps are larger than others, like getting used to semicolons and braces when you’re from a Python background, or entire design patterns such as MVC (Model View Controller) when learning a new framework like Laravel or Rails. Chances are though, you already know more than you’re aware of!

One more thing, please don’t be afraid of admitting you don’t know something! If you’re familiar with Broadwell’s learning competence theory, this is one step closer to mastering something!

Tip 1) Learn by doing

I knew to start writing C# my best bet was to download Visual Studio and get started*, and that’s exactly what I did. I dedicated a few hours to installing the software and building basic programs and algorithms that I knew just so that I could come to understand the syntax and general workflow.

I played around with building console apps, using Winforms to build some basic desktop applications, and when I was ready I decided to start looking around at tutorials online and on YouTube to learn some more complicated functionality, such as accessing databases, accessing and writing to CSV (Comma Separated Value) files, and so on. I remember laughing to myself when I found the StringBuilder functionality was just like the implementation in Java.

You can do as much or as little of this as you want, but I truly believe this is the most effective way to learn it, more so than reading or watching alone.

I realise that this isn’t the only way to develop in C#, especially on macOS or Linux. But this is what we do in my workplace, so it’s how I opted to learn.

Tip 2) Find a good reference guide

(If you want to suggest something to add here, please let me know in the comments!)

I don’t recommend reading textbooks or references from start to finish as an effective guide for learning programming languages. But finding a good reference that you can look at for additional insight is a great way of learning. Here are a few of my favourites for the languages I use most, and they’re completely free (unless stated otherwise):

Multiple / General Purpose

  • Codecademy (JavaScript, C#, Java, etc.)
  • freeCodeCamp (Web Development)
  • The Odin Project (JavaScript, Ruby)
  • General MOOC websites like Coursera, edX, Udemy, and FutureLearn also fall under this category

JavaScript

C Sharp

PHP

Tip 3) Learn from others

Learning from one another is a tried and tested way of aiding you on your learning journey. You’d be surprised what you can learn by sitting down with someone for half an hour when you get stuck. For me, sitting down with my colleagues and having them run through some of the aspects I was unsure about was immensely helpful.

I realise that this isn’t everyone’s cup of tea, nor is it a luxury available to everyone. As a bonus, I recommend giving fellow developers tweeting about the technology you’re learning a follow on Twitter if you use it.

Tip 4) Remember that this is an ongoing process

Don’t be discouraged. Remember, learning is something that developers and other professionals (teachers included!) never stop doing and there will always be gaps in our knowledge. We can’t possibly be experts on absolutely everything, so remember that it’s only necessary to learn what you need – you can always learn more along the way and there’s absolutely no shame in that.

In my experience, smart people are those who recognise that there are things that they themselves do not know.

The smartest people aspire to go one step further and learn what they don’t yet know.

Conclusion

In all, it took me a few days to get comfortable with working in C# and to develop my confidence where I was able to pick apart my learners’ work and debug it comfortably. I realise that I am absolutely not an expert, nor do I claim to be. But I know enough to do my job effectively, to teach it to other beginners, and to start me down the path of continuous learning and improvement in my own skills.

I hope that you enjoyed this piece of writing and that you find it useful whenever you might find yourself needing to learn something in a hurry.

Documentation in Laravel 8 with Enlighten

The importance of software documentation, even in an agile world, is undisputed. Keeping documentation, especially for APIs, up-to-date however can be an additional burden on a development team, and thus automatically generated documentation can help supplement this by producing reference materials. This is where Enlighten comes in.

In this guide, we’ll get Laravel Enlighten up and running, which utilises your existing PHPUnit tests (because you should be writing tests) to produce and publish beautiful, customisable documentation, without needing to run any additional commands.

System Requirements

Enlighten does require both PHP 7.4 and Laravel 8. I don’t know whether it works with Lumen. 

If you’re running anything earlier, such as Laravel 6 LTS, I would instead recommend Scribe. For other frameworks or vanilla PHP applications, try phpDocumentor.

You will also need a secondary database. It does not need to be a different kind of database, but it does need to be persistent.

You also need an up-to-date version of Git. This is unlikely to be a problem on macOS, Linux or Windows Subsystem for Linux, but it gave me some teething problems directly running on Windows 10 under Laragon.

Please also note that these are as simple installation instructions as possible. For troubleshooting and optional installation steps, please check the project’s repository.

Installation

Composer installation

Do not use sudo for any of these commands. That will open a whole Pandora’s box you don’t want to deal with.

Using Composer, require Enlighten into your Laravel project using the following command. If you somehow don’t have it, grab it here.

composer require styde/enlighten --dev

Registering the service provider

Next, add the following to your config/app.php file to register Enlighten’s service provider. If you’re not sure where this needs to go, put it underneath the package service providers comment, like thus:

[
  'providers' => [
    // ...
    /*
     * Package Service Providers...
     */
     Styde\Enlighten\Providers\EnlightenServiceProvider::class,
    // ...
  ]
];

Important: Be sure to end the line in a comma, not a semicolon.

Publish assets to the public directory

Run the following command to publish Enlighten’s assets to your public directory. Without this, any documents you generate will lack any CSS formatting or JavaScript.

php artisan vendor:publish --tag=enlighten-build

Integrating Enlighten into your tests

In order for Enlighten to activate during testing and to have access to test data, it will need to be imported and initialised during the setup phase of your tests. You can do this in your TestCase.php abstract class, or in individual test files.

For example:

<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Styde\Enlighten\Tests\EnlightenSetup; // import this trait

abstract class TestCase extends BaseTestCase
{
  use CreatesApplication;
  use EnlightenSetup; // and use said trait here

  protected function setUp(): void
  {
    parent::setUp();

    $this->setUpEnlighten(); // the final piece of the puzzle
  }
}

Important: I believe you need to still call parent::setUp() in your setUp() methods within your tests.

Setting up the secondary database

As aforementioned, Enlighten needs another database to record information. The easiest way to do this is to create another database with the same name of your existing one, except with an _enlighten suffix.

For example, if you have used a MySQL database named laravel, you can create another one called laravel_enlighten which will be used automatically. This assumes you’re using the same database connection, credentials, and driver.

Once you’ve made it, run your migrations to get it set up:

php artisan migrate

Optional: Custom database setup

If you need to use something else, add a new entry to your config/database.php file with the name enlighten. This can support a different driver, credentials, database name, etc. You can add this information as custom entries in your .env file – possibly with an _ENLIGHTEN suffix for clarity.

For example:

'enlighten' => [
  'driver' => 'mysql',
  'host' => env('DB_HOST_ENLIGHTEN', '127.0.0.1')
  'port' => env('DB_PORT_ENLIGHTEN', '3306')
  'database' => env('DB_DATABASE_ENLIGHTEN', 'laravel_enlighten')
  'username' => env('DB_USERNAME_ENLIGHTEN', 'root')
  'password' => env('DB_PASSWORD_ENLIGHTEN', '')
// …
],

I think that you could use an SQLite database in theory, but I haven’t tested this and generally stick to the defaults.

Don’t forget to run your migrations if you choose this route.

Running Enlighten

Once you’ve set everything up, Enlighten will run when you run your test suite:

php artisan test

You can then find your new documentation at the yourwebsite.test/enlighten/ URL.

What’s next?

This guide was designed to get Enlighten up and running as easily as possible. More customisation and configuration options are available to make your documentation as detailed and organised as possible. You can read more on the project’s repository.

I hope that you’ve found this guide useful and I encourage you to check it out with your Laravel API projects! It goes without saying, but Enlighten wasn’t written by me – it’s an open-source project headed by Duilio Palacios and Jeff Ochoa.

Thank you so much for reading.