Playing with web frameworks

Foreword

I'm researching several web frameworks in order to create a web application that I need to, that also should work as a web site on the Internet, and will have API to integrate things into other web-sites, if clients does not want to use that site.

For the task I started with two frameworks:

  1. fpWeb – aka fcl-web
  2. django

I do not want to try Rails, because I find the logic behind it very disturbing. The Rails framework rewrite the language, rather then adding libraries to use. I think that it is not the proper way to write libraries. So I decided not to try it at all, even though I really love the Ruby language itself.

fpWeb

So I started testing fpWeb, and I must say that it takes a while to get used to it and the way it does things, but once I figured out the basics, I find it really enjoyable to write a CGI (I always hate to write html/css stuff though, and that's regardless of the language for the server side) application.

fpWeb works in very different mindset then most modern web frameworks I have ever worked with so far. On one hand it appears that everything chosen for you, that is the template engine, session engine etc.. But  on the other hand, you can actually use what ever you want, just decide on something and go for it.

Unlike most frameworks, it does not arrive bundled with all of the required tool. It allows you to use the tools that you want to use by just using what arrives with FPC and Lazarus. But also with 3rd party tools and libraries. Just like any other application. So instead of looking for a chart tool for fpWeb, you can use taChart, and create an image of the charts.  You can use the bgra tools to make it look prettier and use DataSet based non gui component for database access, or direct API, or whatever you want to… It's all up to you !

The template structure is a bit different then what we know from erb, and even from django's templates. No logic and no code on the view side ! only tags that will be replaced in our CGI code ! We choose how the tags looks like and how we work with them. And if no code is set for a specific tag ? well, the engine will remove it anyway for the rendering.

That approach took me half a day to understand. Not the design of templates, but how to create sub templates that the variables there will also be parsed, but it wasn't hard to understand, once you realized the mindset of the engine.

Another big advantage of fpWeb, is that it is really easy to convert the application between CGI, FastCGI and Apache's module. It takes something like 4-6 lines of code to do so.

And like with other applications, you can share your code with many other applications or several modules of your CGI, and even use the same code for more then one CGI application.

django

I never understood Python too much. It have few unreadable issues, in my mind at least.

For example:

class Example :
    def __unicode__() :
        return 'bla'

    class SubExample :
        def say_hello :
            return null # not really needed I know

    def do_something() :
        # ....

I find this issue unreadable. Do you have a bug here ? does it work like you wanted ? You can not really tell here. Most Pyhthon developers will say now "huh?"

When you wrote do_something, have you meant to see it belong to SubExample, but have a bug with your spaces ? Does SubExample should be a sub class or should it be a standalone class ? And the questions just keep on popping into my head on this short code.

The indentation as a way to set code blocks that explain what belongs to where is very unreadable (for me at least) as a syntax. On "normal" languages, even if my indentation is wrong, it will not effect the code logic or flow. And it's really simple to fix btw… But on Python you never really fully understand if things are intentional, or if that is a bug. I know that some people will say that you can always document it, but that just misses the point of readable code. Comments should arrive to explain why, or what, or "the way of". Not the language itself. Code with variable assignment of a value with a comment of "adding this value to the variable", well that's a noise, not a comment.

But it's not the only unreadable thingy that the language have. Here is another example:

"/^hello.*$/"

What will happen ? Does it a string or a Regex ? should I escape it or not ? Why will it translate as a Regex ? Or why will it not ? (I found it in django's route translate it into a regex …) On Ruby for example, regex code is belong to the Regexp class. You understand that it's not a string due to syntax. If django had something like regex("/^hello.*$/") then I would have known that it will have some sort of regex translation. But a string that in a magical way translate as a regex, well, that's unreadable, for me at least. There are many other issues with the language itself.

Unlike Rails, it make sure that you understand from where things comes from (yes, you can do the same in Ruby, but people that arrive from Rails, usually does not do that 😦 ).

But like with Rails, some tools, that was not written specifically for django, will remove efficiency and will bite you somewhere, and you will loose something on the way because of that.

The admin interface support of django is really cool, and save a lot of time and effort for the developers. I think that if you require administration interface for a product/website it makes much better choice then "clean" rails (rails does have plugins that add such support as well).

Conclusion

I need to play more with django. I really dislike Python way of doing things as you understand, but I can accept that evil, like the way I accept coding with C when I have no choice but something to gain.

fpWeb is more or less like PHP before the usage of any other framework, but more readable, maintainable and flexible.  It will take more time to implement things over fpWeb then django, but I will enjoy more working with fpWeb then with django.

So if  this was not a work related decision, I would go with fpWeb, but time is very important, so I think I'll go with django 😦

4 מחשבות על “Playing with web frameworks

  1. DA
    void func(void) {
    	return "hello world";
    }
    
    do_something(*func);
    

    C is very unclear. Unlike Java you can't really see what's going on. In the example above, did we pass a reference to the function or a pointer? what will the function return?

    When you read something like this, you can tell that the person who wrote that has no idea what's C.

    Why not take the time and learn python before you criticise it for things which only come to show you know nothing about it. To me at least the paragraph above is pretty much the way you describe python.

    1. ik_5 מאת

      I do not find it to be the same at all.
      Because you declared a function without any parameters, and you pass it. The compiler should place an error about it.

      The code I wrote was actually a code that someone showed me (different names of things) how to use django, and that person actually knows a lot of Python …
      So how would you rewrite the Python code I wrote above to be more Python ?

  2. DA

    I'll ignore the "this" notation or static methods which you didn't use. The problem lies in your description of the language. No python programmer will have any problem distinguishing between a subclass and a normal class, the indentation makes it clear. You don't use the language; and by the looks of it you have yet to learn its syntax so it might confuse you. The code you wrote above won't run and i'll let you figure out why that is.

    Take a couple of weeks and use the language, with an open mind. Than make an informed judgement and criticism.

  3. שי

    The Python code works the way it looks; you don't have to be super-attentive to discern the real structure of code, as you sometimes have to in Pascal:

    if (x<0)‎ then
       x := -x;‎
       booyah(x);‎
    frob(x);‎
    

    Of course, the above is contrived. Of course, you can see that it has a problem; much like in the Python case, it isn't clear if you made an indentation mistake or a logical one (I can hear you say, "but at least it's clear that there's a problem"). However, logical errors usually make themselves apparent in testing; while indentation errors can just be left in the code as mines for the unwary.

    Python prevents this latter kind of errors. You cannot make an indentation mistake that isn't also a logical mistake. You're also a Rubyist, so supposedly you know about testing. Actually, wondering whether visible code structure is "just an indentation mistake" seems to show a mindset that refuses to take indentation seriously.

    Regular expressions in Python are built from strings, there is no special syntax for REs. It is common to pass around strings which will be turned into REs later, because strings are easier to manipulate (and it is more efficient to compile a string into a regex as late as possible). Your complaint there comes down to "API? TL;DR!".

    Some nitpicking: SubExample in your pseudo-code is not a subclass but an inner (or member) class. The term "subclass", everywhere I've seen it used, refers to inheritance. "null" is called "None" in Python.

כתיבת תגובה

הזינו את פרטיכם בטופס, או לחצו על אחד מהאייקונים כדי להשתמש בחשבון קיים:

הלוגו של WordPress.com

אתה מגיב באמצעות חשבון WordPress.com שלך. לצאת מהמערכת / לשנות )

תמונת Twitter

אתה מגיב באמצעות חשבון Twitter שלך. לצאת מהמערכת / לשנות )

תמונת Facebook

אתה מגיב באמצעות חשבון Facebook שלך. לצאת מהמערכת / לשנות )

תמונת גוגל פלוס

אתה מגיב באמצעות חשבון Google+ שלך. לצאת מהמערכת / לשנות )

מתחבר ל-%s