Trongate Website Homepage

Regarding Coding Style

The Trongate framework achieves best-in-class benchmarks by minimizing overheads to the greatest extent possible. This philosophy extends to Trongate's approach to syntax, or 'coding style', where the following three primary goals have been identified:

Embracing Modern PHP for Better Web Development

The inner workings of the Trongate framework are contained within a directory named 'engine'. Every function and method within Trongate's engine directory comes complete with doc blocks, access modifiers (i.e., public/private/protected), type hinting, and return types. This makes Trongate one of the few PHP frameworks that utilize well-documented, modern PHP syntax.

Nevertheless, there are a few nuances within Trongate's syntax that make it stand out from other PHP frameworks.

Harmonizing PHP with C Roots

One of Trongate's goals is to provide developers with a coding experience that closely resembles working with pure PHP. For this reason, the code examples used throughout this documentation are written in the K&R (Kernighan and Ritchie) coding style.

The K&R style is a popular coding style, especially in C programming, as it is compact, avoids ambiguity, and can save vertical space in the code. It is named after the authors of the classic book "The C Programming Language," Brian Kernighan and Dennis Ritchie.

Did you know? PHP was originally built using the C programming language, influencing many of PHP's core functionalities and syntax. Notably, the vast majority of functions within PHP are written in snake case, a style of syntax that is favored by Trongate.

Key Characteristics of K&R Style

Example


function hello_world() {
  echo "hello world";
}

Additional Coding Conventions

Trongate encourages the following practices to streamline development:

Trongate provides developers with a syntax that mirrors PHP’s core characteristics, promoting familiarity and consistency. The use of snake_case, for example, aligns with PHP's own syntax, which extensively utilizes snake_case due to its roots in C programming. This design choice ensures that Trongate feels natural to PHP developers and maintains consistency with the underlying language conventions.

How Snake Case Prevents Ambiguity

Trongate's commitment to using snake_case in its syntax is more than a stylistic choice; it is a strategic decision that enhances clarity and consistency, particularly when contrasted with the ambiguity that can arise in other languages that use different case conventions.

For example, in languages like JavaScript, function names such as getElementById() and properties like innerHTML are examples where camelCase is standard. However, these names often lead to confusion - should it be getElementByID() or getElementById()? Similarly, should one write innerHTML or innerHtml? Such variations can cause errors, especially for those new to the language or when switching between projects with differing naming conventions.

In contrast, snake_case provides a straightforward approach to naming: all letters are lowercase and underscores separate words. This method removes ambiguity regarding the capitalization of letters, making it clearer and easier to remember. For example, in Trongate, a method to get an element by ID would consistently be named get_element_by_id, leaving no room for capitalization errors. This consistency is particularly valuable in a framework like Trongate, where the simplicity and predictability of snake_case align seamlessly with PHP's own syntax, further reducing the cognitive load on developers and preventing common syntax errors. Such practices underscore Trongate's commitment to developer efficiency and error reduction, distinguishing it in a landscape where small differences in naming can lead to significant debugging challenges.

Trongate's Approach to Namespaces and Access Modifiers

Trongate simplifies development by minimizing the use of access modifiers and namespaces. This streamlined approach contrasts with the more complex conventions often found in traditional PHP frameworks and aims to accelerate development processes.

While adaptation to Trongate’s style is optional, many developers find that embracing this streamlined approach significantly enhances efficiency once they become accustomed to it.

Regarding Modern PHP Syntax

Recent versions of PHP offer developers the opportunity to incorporate advanced features such as type hinting, doc-blocks, return types, and annotations. In PHP 8, constructor property promotion was introduced - giving PHP developers the ability to define and initialize class properties directly in the constructor parameters. These features can enrich code with detailed type information and metadata, enhancing clarity and robustness. However, their use remains entirely optional.

While Trongate fully supports these modern PHP features, they are not used in the framework's documentation. This approach is adopted to maintain simplicity and ensure that examples are accessible and easy to understand, especially for those new to the framework or to programming in general.

PHP developers who are accustomed to using features like doc-blocks and type hinting are encouraged to continue leveraging these elements to enhance code quality and maintainability.

Conclusion

A comparative analysis of Trongate's syntax against that of other popular PHP frameworks uncovers significant distinctions. These differences, which include omissions of common practices, unique naming conventions, and a more concise use of characters, set Trongate apart in the PHP framework landscape. Such differences may initially be surprising or even alarming among developers accustomed to other frameworks.

It is important to acknowledge, however, that these deviations from the norm are not arbitrary. Trongate's syntax has been meticulously crafted with specific intentions, rigorously aligning with the framework’s primary goals of prioritizing operational efficiency and eliminating room for error. By streamlining coding practices and reducing potential pitfalls, Trongate significantly enhances developer productivity, ensuring that each line of code is both purposeful and effective. This approach not only champions a more efficient coding strategy but also underscores Trongate’s commitment to advancing PHP development through thoughtful innovation.