How to develop more comfotrable?

7 years ago by David Grudl  

The new version of Nette 2.3.7 brings a lot of improvements, but one of them you'll quickly love. It's the error messages that try to give you a hint if you make a typo.

I'm sure you've run into a similar error before:

You want to render a component in a template and it says it doesn't exist. This can have a variety of causes, from some omission on the presenter's part to a bug in the template. Or is the component named something else?

Worst of all, there are trivial typos that you can't see, so you check all the possibilities several times and spend quite a bit of time on it before you discover the error.

But the latest version of Nette has a handier error message:

Did you mean ‘signInForm’? Aha! It's immediately clear that a typo was at fault, and you can fix it right away.

If you've ever been stuck on case for a long time, i.e. if {control MyComponent} gave you the error Component with name ‘MyComponent’ does not exist, you'll appreciate the addendum Did you mean ‘myComponent’? all the more.

Let's go to Nette\Database. Error in the database column name? Again, you get it on a silver platter:

Nette suggests typos in the names of functions, methods, variables, etc. If you are developing in an IDE, you shouldn't get errors like this; on the other hand, few IDEs can fully hint in templates, for example. Whether you make a mistake in the name of a filter or a macro:

Or in the name of a variable:

The did you mean news of increasing convenience does not end with the catchphrase. Nette will now alert you to a number of other, previously hard to detect, errors. Such as the missing []

$myForm->onSuccess = [$this, 'myFormSucceeded'];
// namísto správného
$myForm->onSuccess[] = [$this, 'myFormSucceeded'];

or missing ()

{foreach $form->getErrors as $error}
// namísto správného
{foreach $form->getErrors() as $error}

or quite dangerous omissions, since $user->isLoggedIn is always truthy:

{if $user->isLoggedIn} ... něco tajného ... {/if}
// namísto správného
{if $user->isLoggedIn()} ... něco tajného ... {/if}

This will now lead to the warning Did you forget parentheses after isLoggedIn?

Note: if you deliberately write a method without parentheses in your code, i.e. $cb = $obj->getItems, because you want to use the Nette\Object property, which stores a callback to method getItems in $cb, and a warning appears, please use the standard PHP notation, i.e. $cb = [$obj, 'getItems']. In correct normal usage, the warning is not displayed.

Furthermore, Latte will warn you if you use a modifier in a place where it is ignored, such as:

{if $var |filter}

Did you mean “more comfortable”?

The new version of Nette is here to make your development easier and more comfortable. And you'll really realize how godlike that is when you try it out.