Trongate is PHP's first (and as far as I can tell only) stability-first framework. This means, we who look after the framework value stability above all else. Please do not assume that this means Trongate never gets improved. The Trongate ecosystem, including the framework, gets updated frequently. The evolution is constant and, for me, it's a full-time job. It has been that way for around the last four years. You only need to go to GitHub to check out all of the activity for yourself. Go ahead.

Let me assure you that stability will continue to be Trongate's calling card. It's our flagship feature. Yes, we do have the fastest PHP framework (prove me wrong!) - but I don't really care about benchmarks (truth be told). I care far more about stability. It's everything. To be able to constantly improve a framework but without breaking anything is an almighty task but so far we've pulled it off. I'm optimistic that we'll continue to keep Trongate stable, moving into the future.

Every once in a blue moon, however, a significant shift comes along with regards to how we do things. One of those moments is upon us now and it's to do with access modifiers. I'll be delighted to explain what all of this means but first I want to stress as strongly as possible that your code is not going to break. Moreover, I'm not in the business of enforcing anything. Even though I've had pressure to 'enforce' various types of syntax and coding styles, it's not for me. Other frameworks do that. Trongate is different. My hope is that you're going to code in a way that feels good for you. One or two naysayers may assume that I'm being slightly amateurish by saying such a thing. I'm not. The truth is, Trongate's architecture is truly modular. In other words, everything is made of self-contained modules. So, with Trongate, it's perfectly possible and normal for developers to collaborate on large projects - even if they have different coding styles. I insist, no developer worth their salt is going to hit a dead end if you put your opening curly bracket on a new line. Do what makes you feel good!

That being said, allow me to discuss this syntax change that's coming up. I'll tell you what the change is, why this decision is being made and what to do next (spoiler alert - you don't have to do anything!).

The Nature Of The Change

As some of you may know, the 'engine' directory of the Trongate framework contains the inner workings of the framework. Within the last few months, this entire directory has received a major upgrade. That's because every single function, class, and method within Trongate's engine folder is fully documented. I say 'documented' in both the technical sense and in the sense of 'we have beautiful documentation written and due for release soon'. Anyway, if you look inside the 'engine' directory and choose some random PHP files, you'll surely notice that all of the functions and methods within those files contain:

  • Doc blocks
  • Type Hinting
  • Return Types
  • Access Modifiers (but only for methods, mind you!)

If you are not sure about what those things are or what they mean, don't worry. They're optional features. What's important, I think, is that the inner workings of the framework have been meticulously crafted in a way that follows best practices as closely as possible. So, we have a very solid 'engine' directory. I'm happy with it and I hope you are too.

However, when it comes to the 'modules' directory, things suddenly get a little bit 'Woodstock'. In other words, it's a bit of a hippy free-for-all. In the 'modules' directory, you rarely see things like doc blocks, type hinting, return types, and access modifiers. Instead, you'll occasionally see things like the 'underscore-first' naming convention. This is where method names are given an underscore as the first character to signify that they cannot be invoked via the URL.

The 'underscore-first' naming convention is an essential part of how Trongate works. It's a huge time-saver and if we didn't have it, we'd have to start thinking about using YAML files or some other ghastly configuration-based system.

There is a widely held misconception, in web development circles, that the 'underscore-first' naming convention has something to do with making methods 'private'. I can assure you, it doesn't. If you require more information about that then, I have a couple of very boring YouTube videos where I go into all of this in detail. Those videos are here and here.

Whilst we'll be keeping the 'underscore-first' naming convention, the big syntax change is that we're going to start using access modifiers everywhere. An access modifier is a word that we put at the start of a method name that specifies the level of access or visibility that the method has in relation to other parts of the application. In PHP, there are three main access modifiers: public, protected, and private. These modifiers control the visibility and accessibility of class members (properties and methods) within the class and its subclasses. Each access modifier provides a different level of access control, allowing developers to define how class members can be accessed and manipulated within their codebase.

By default, PHP assumes methods to be public if access modifiers have not been explicitly declared. My personal coding preference, through the years, has been to leave out access modifiers and to use the 'underscore-first' naming convention as a speedy alternative to having to write 'private' in front of lots of function names. This is also the way things have been done when it comes to Trongate, generally. I made this decision for two reasons:

  1. Speed (leaving out access modifiers means fewer characters to type)
  2. To make the framework more attractive to JavaScript developers

With regards to the second point, the idea was simple. If we leave out access modifiers then it's one less thing to learn. Sounds like a good idea? Well... maybe it is. However, recently it's an idea that I have started to call into question. What I've now started to realize is that the 'speed' argument can be easily dismissed by simply introducing keyboard shortcuts. This is something that all developers who care about productivity should be serious about. As for the second point, I'm increasingly starting to realize that PHP is very different from JavaScript. To pretend otherwise is like putting a shirt and tie on a poodle.

Most importantly, I've come to realize that the addition of access modifiers encourages developers to really think about their code. I've been using them in my own work, recently, and it has forced me to write code in a manner that is more precise and more deliberate than before. Those of you who make the switch to coding with access modifiers will find yourself constantly asking questions like:

  • What is the main purpose of this code?
  • Is this code repeating something that I've already built?
  • Will other classes be able to invoke this code?
  • What are the likely upgrade scenarios for this code, looking to the future?

These kinds of questions are all good. I can assure you, they will make you a better developer. You'll make fewer mistakes and whilst the act of physically typing the code may potentially take longer, you'll ultimately end up being more productive because of fewer errors and less repetition.

By my estimation, the single biggest technical mistake that developers make is building the same thing over and over. It causes problems and it wastes massive amounts of time. My challenge and my invitation to you is to join with me in a slightly different coding style. It's a coding style that is based on precision. It's all too easy to sit for hours and hours, writing dozens and dozens of PHP functions and methods. The trouble is, it leads to rubbish code. So, what I'm trying to encourage is a different type of web development. When you write a function or a method it should be an event. In other words, it's important. It matters. It's something worth getting right the first time. It should be something that you should be able to look at with a sense of pride. Sign it with your name, like an artist, if you wish!

As you can see, we're moving towards a coding style that is very meticulous and thoughtful. So, it's going to be access modifiers all around for Trongate. It'll take a few weeks for this to get rolled out but you'll see it soon. Don't worry, you do not have to use them if you don't want to. None of this will break your existing code.

What Caused This Change?

Recently, some of us have been working on new documentation for Trongate. You'll see that soon, hopefully. One of the things we were eager to do was document all of the publicly accessible methods within the framework. However, without access modifiers, this seemingly simple task turned out to be far more complicated than it should have been. Introducing access modifiers will certainly make our upcoming documentation clearer and easier to understand.

Also - on a slightly more personal note - I started building a online discussion forum recently. I've built a few online discussion forums in the past (including the Help Bar) and I was confident that I'd be able to build something in a few hours. Unfortunately, however, I got into a bit of a tangled mess. It took far longer than it should have. The main mistake I made was writing too much code too quickly. All of this has invoked a rethink about matters to do with coding style. So, I'm trying to switch to a coding style that is more deliberate and more thoughtful. I think that the addition of access modifiers will be an essential part of this change. The best argument that I had, in the past, for not using access modifiers was speed. However, I now consider that to be a weak argument. Real coding speed is not achieved by typing fewer characters but by coding in a manner that is thoughtful and precise.

Finally, I have to give a shoutout to 'Doranov' - a member of our community who brilliantly argued the case for making the switch.

What About Votes?

I had discussed this on a YouTube video and, initially, everybody seemed happy with the way things are. A few days later, the issue came up again and I ran a poll on a live stream - on YouTube. The result was that 77% of voters were in favour of the switch. This was before I had expressed my own personal preference. Most importantly, I took the time to get opinions from people who are heavily involved in the framework. I'm speaking about Founding Members like 'Dafa', who has contributed hugely to Trongate and who has been with us since day one. Their opinions count massively and they appear to be happy for this to go ahead.

In the near future, we'll have a formalised voting system added to this website. I look forward to that. In the meantime, however, we have a massive to-do list for Trongate and a boat load of work that needs to get done to make our eco-system perfect. Keep in mind - this is not going to be a breaking change for anyone. It's just a syntax change and it's not being enforced. Don't worry about it!

It's a funny old time for Trongate, isn't it? Seems to me that the framework is becoming a little bit more grown up. Just a little bit.

Keep breaking the rules!