Wisdom: Golden rules for TYPO3 extension programmers

5 05 2007

[1] Master PHP: You should know at least the content of the PHP Language Reference.

[2] Master typoscript: Even if you don’t like typoscript and you want to code PHP instead, you need an overview of Tsref. It contains important documentation about dealing with links and images and some other valuable information for programmers.

[3] Read the TYPO3 Core API: It’s the most important document for TYPO3 programmers. Almoust 75% of the content directly matters.

[4] Read the TYPO3 Coding Guidelines: Learn how your sources should look like. Learn about DB connectivity and security issues. Learn how you correctly access the environment variables, so that your extension will run under changing environments.

[5] Look into the sources often: Every secondary documentation becomes obsolate sooner or later. The only documentation you can always rely on are the original sources. To be able to visit them at any time, is the real advantage open source development.

[6] Configure your editor in a way, that you can access the sources to search in them. Hardcore developers take emacs or vim and make use of the automatic tagging mechanisms. The others use the features of IDEs like eclipse, to access the sourcecode information. Your editor has to be UTF-8 capable.

[7] Use autoindnet with tabs.: Learn how to use your editors auto indenting feature and use tabs not spaces to indent your code. That’s to accord with the coding guidelines, to enable the community to work hand in hand.

[8] Make yourself a (typo)link specialist: If you deal with forms or internationalization or realurl or caching or indexing or accessibility or frames or whatsoever. Your extension will only work smoothly when your links are build with the right technology. Also typolink has some quirks you have to master.

[9] Learn to use the typolink function: The right technology for frontend extensions is always the typolink function. Every link that doesn’t use it directly or indirectly will quickly break as soon as you run your extension in a different environment.

[10] Avoid the link functions of tslib_pibase: Although this link functions use the typolink indirectly, they are to messy to invest your precious time. Learn to use the one and only typolink function directly. It’s your swiss army knife. Consult TSref for it’s many parameters.

[11] Never use no_cache: Every extension that works with the no_cache parameter is an ugly extension. It’s a killer for indexing and performance. Use a USER_INT where indicated.

[12] Don’t rely on kickstarter generated code: The kickstarter is usefull for you to get started with extensions, but the generated code is rather poor. The kickstarter produces nonspeaking plugin names like pi1, pi2. It generates forms with the no_cache parameter in a hidden field. Exchange the generated code against your better code.

[13] Learn from the core how to document code: The sourcecode, Kasper has written, is very excellently documented. Document your own sourcecode in a similar way for the sake of others and yourself.

[14] Learn from the core how not to code: Understand me right. TYPO3 is a precious donation to the world. At that time there has nothing been comparing it. Here I talk about coding style. The classes of the core are usually to big. The functions are far to long. Loops are nested by to many levels. The namings are cryptic and abbreviated. The result: Often you can’t understand core code easily, especially some important, central parts. It’s hard for people to fix and improve them. The solution is a complete recode for version 5.0. Always write code in a way, that other people and yourself can understand it easily. If your code looks that simple, that a non programmer can understand it without explenation, your code is good code.

[15]Use UTF-8: Even if your project is starting with one language only, times will come when internationalization is requested. Be prepared. Use UTF-8 from begining and you will never see the hell of multiple charactersets. Use an utf-8 capable editor. Use Mysql 5. Set $TYPO3_CONF_VARS['BE']['forceCharset'] = 'utf-8'; $TYPO3_CONF_VARS['SYS']['setDBinit'] = 'SET NAMES utf8;'; in localconf.php. Set the tables to utf8_general_ci.

[16] Keep lists below 20: The maximal size of a list that a person can overview easily is somewhere between 12 and 20. Keep all lists below that size, the number of lines within a function, the number of functions in a class, the number of classes within a directory. If any list grows bigger, it’s time to consider a split and reorganization.

Here I end up with a list of 16 to meet the last rule. You see it’s the upper limit of what you can bear. Avoid to ask more from others. So you managed to read them all? I hope you will profit by one or other of the rules.


Actions

Information

4 responses

1 08 2007
Jochen

Hi Elmar,

really a nice, brief and complete overview!!! Nice one.

Just added your blog as feed in my thunderbirdy.

Cheers,
Jochen

8 03 2008
Oliver Leitner

I have a question about #10
Why?
You say its messy, may you explain why?

Also, since you are at the functions level…
Two more things to add in my opinion:
Use SQL Statements from the Typo3 Api, and use the AdoDB part if possible.
Use Functions, rather than the usual long php all in one code, example for a good code might be the extension “seminars”

Just my few cents…

7 07 2008
Ram

Hi Elmar,

Really Nice one.I m having a doubt how to integrate php files in the typo3 using Extension.

17 02 2009
Wisdom: Golden rules for TYPO3 extension programmers | Sprinkesnirg

[...] Wisdom: Golden rules for TYPO3 extension programmers « TYPO3 FLYERS Dieser Eintrag wurde veröffentlicht in Typo3, Webkram und getagged extensions. Bookmarken: Permanent-Link. Kommentieren oder ein Trackback hinterlassen: Trackback-URL. « My own free MobileMe replacement [...]

Leave a comment