Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lift and type safety

Tags:

scala

lift

I am learning Lift now. When I read about templates, I understood that they have a lot of things which aren't typechecked at compilation time:

  • Templates might contain references to non existent snippets
  • SiteMaps might refer to non existent pages
  • Snippet dispatch methods take string parameters where we can easily make a typo

Are there any alternatives to make this problems less severe, i.e. external code checker or options in the library which would allow do the same but in a type safe way? Or may be there is another web framework which is more strict in this relation (may be in other language).

like image 365
Konstantin Solomatov Avatar asked Nov 13 '22 02:11

Konstantin Solomatov


1 Answers

Type checking is a compile time feature of strongly typed languages such as Scala or Java that allows the verification of the signatures and of the relationships among types. Such checks will prevent you from passing a parameter of type Banana when a parameter of type Meat is expected, or to assigning a String to a variable of type Int. Typically, in dynamic languages such as Ruby or Javascript, this is not possible

What you are looking for is not a type checker. You do not want to verify that your program is syntactically right, but rather that it behaves correctly, and the solution for that is called automated testing.

You are perfectly able to write code which is syntactically right, but behaving wrong:

public boolean isTrue(boolean value){
        return !value;
}

If you think it the other way around, how would you test a compile-time the correctness of a template which needs to be filled with some data?

 <!-- importing a snippet depending on the value of a variable -->
 <import src="${snippetName}.xml"/>

You can't, because all your variables at compile time have absolutely no value. That's why automated testing is important and writing test cases for your application cannot be replaced by compile-time checks.

like image 180
Edmondo1984 Avatar answered Dec 27 '22 14:12

Edmondo1984