12

I am familiar with both Python and C++ as a programmer. I was thinking of writing my own simple web application and I wanted to know which language would be more appropriate for server-side web development.

Some things I'm looking for:

  • It has to be intuitive. I recognize that Wt exists and it follows the model of Qt. The one thing I hate about Qt is that they encourage strange syntax through obfuscated means (e.g. the "public slots:" idiom). If I'm going to write C++, I need it to be standard, recognizable, clean code. No fancy shmancy silliness that Qt provides.
  • The less non-C++ or Python code I have to write, the better. The thing about Django (Python web framework) is that it requires you pretty much write the HTML by hand. I think it would be great if HTML forms took more of a wxWidgets approach. Wt is close to this but follows the Qt model instead of wxWidgets.

I'm typically writing video games with C++ and I have no experience in web development. I want to write a nice web site for many reasons. I want it to be a learning experience, I want it to be fun, and I want to easily be able to concentrate on "fun stuff" (e.g. less boilerplate, more meat of the app).

Any tips for a newbie web developer? I'm guessing web app frameworks are the way to go, but it's just a matter of picking one.

user52875
  • 3,020
  • 22
  • 21
void.pointer
  • 24,859
  • 31
  • 132
  • 243
  • I wouldn't discount hand writing HTML. HTML is fundamental to how the web works and writing it by hand for your first app (provided it's not a *huge* app) would be a good idea IMO. – Andy Gaskell Aug 17 '09 at 19:54
  • In my opinion, HTML is layout just like wxWidgets and QT are layout as far as I've seen, however both of those GUI frameworks have tools to assist in auto-generating that layout information. It just doesn't make sense to me to hand-write something that a tool could write better, faster, and easier. It would be ideal to structure my web-page through a GUI HTML Layout tool and then paste that generated HTML into my app to send to clients. – void.pointer Aug 17 '09 at 20:06
  • Sure, if you want to go down the route of autogenerating HTMLs create them in Dreamweaver, or similar, and use that in Django template. – agiliq Aug 17 '09 at 21:02
  • 1
    @void.pointer: No, it's nothing like those. The layout you generate in QT is parsed specifically by QT. HTML is parsed by a half dozen different browsers, none of which can agree on how it should be rendered, and according to a underspecified standard. You can autogenerate it, but you have no guarantee that it'll actually look correct. So far, I haven't seen any framework which was able to generate halfway acceptable HTML. They generally produce big bloated messes that are impossible to maintain. And you need to maintain it to ensure it renders correctly in every new browser. – jalf Aug 17 '09 at 22:32
  • 4
    Wt does not require strange syntax or a fancy preprocessor. Unlike Qt, it's all pure C++ – user52875 Oct 14 '10 at 11:32
  • Small correction: While Wt uses slots and signals, it doesn't change C++ syntax like Qt does. It uses Boost signals and there's nothing inherently dirty about that. – Tyler Aug 16 '14 at 22:56

7 Answers7

12

I would go with Wt because:

  • You already know C++
  • It has a nice layout system, so you don't need to know lots of HTML
  • It is very well written and a pleasure to code in
  • Your deployed apps will handle 50 times the load of the python app on less hardware (from experience with pylons apps, 10,000 times the load of a plone app :P)
  • It has all the libraries that the guy in the first question says it doesn't and more
  • Web 2.0 isn't an after thought; it wasn't designed on a Request+Response model like all the python frameworks (as far as I know), but on an event driven interactive model.
    • It uses WebSockets if available
    • Falls back to normal ajax gracefully if not
    • Falls back to http for browsers like linx
  • It is more like coding a gui app than a web app, which is probably what you're used to
  • It is statically typed and therefore less error prone. Does def delete(id): take an int or a string ?
  • The unit tests (on my apps at least) take 10-100 times less time than my python app unit tests to run (including the compile time)
  • It has a strong and friendly community. All my email list posts are answered in 0-3 days.
matiu
  • 7,469
  • 4
  • 44
  • 48
  • 3
    Now I'm working with a django app, I'll add another Wt and C++ advantage: it's more explicit and less magic; I'm finding with the django app, most of the code is in the library and my app code is mainly callbacks; this makes it a bit difficult to debug as I don't know the order that my code will be called in. On the flip side the django code is much less than any Wt app and gets a lot done with a small amount of code. Also the django app uses a lot more resources when idle due to polling and DB reads. (Wt polls too, but very small packets and seems to have better DB caching and notifications). – matiu Jul 15 '12 at 22:04
  • -1: if you develop applications without knowing HTML, you'll get crappy code, the GUI like model is not good for web, also Wt does not even support caching and its session model will always limits its performance – Artyom Aug 29 '12 at 12:09
  • Also the Wt template engine is (sorry) a joke. – Artyom Aug 29 '12 at 12:10
  • 5
    I like the GUI model for web dev, and believe it is the future, just look at Chrome OS. You have a valid point with the session model. It can slow down certain parts of the app; however as with most frameworks, the bad bits can be worked around to a certain extent. You can add caching on the front of Wt, at least for style sheets and images, and even for the initial loading/landing page. They can even be served out of a CDN. Could you please elaborate on the good/bad of the template system ? IMHO it does a very good job. – matiu Sep 07 '12 at 01:40
9

If you'd like to avoid writing HTML, you could try GWT. However, in my experience, using an intermediate framework to generate HTML and ECMAScript never works anywhere near as well as hand-writing the pages.

[edit] nikow mentions in the comments that Pyjamas is a port of GWT to Python.

Regarding the language, if given the choice between C++ and Python I would pick Python 100% of the time. Even ignoring the obvious difference in abstraction between those languages, Python simply has more useful libraries than C++. You don't have to write your own development-oriented web server -- Django comes with one. You don't need to write a custom template library -- Python has Genshi. Django comes with a capable ORM layer, or for even more control you can use SQLAlchemy. It's barely a contest.

John Millikin
  • 197,344
  • 39
  • 212
  • 226
  • 3
    Note the Pyjamas project, which allows you to use Python instead of Java for GWT. – nikow Aug 17 '09 at 21:29
  • 1
    If this wasn't already the selected answer, I'd encourage posting Pyjamas as its own answer. – quark Aug 18 '09 at 03:40
  • 4
    Wt, the c++ library has both a webserver in built, and a powerful templating language, plus an ORM layer, plus a good base for unit testing with fake requests and whatnot. – matiu Jul 02 '12 at 19:47
8
  • Django is good point to start web development it is great framework
  • If you look for C++ take a look on CppCMS, it is much more close to Django, it is not like Wt that mimics Qt.

In any case, it is really depends on your needs. C++ can be used for embedded or high performance web applications, but for medium range web sites Django would be better. (and I'm developer of CppCMS)

Artyom
  • 31,019
  • 21
  • 127
  • 215
  • +1: Also, Django forms do not force you to write HTML. The page as a whole must be in HTML, but input form HTML is specifically taken away from you. – S.Lott Aug 17 '09 at 21:07
1

I think you better go firt python in your case, meanwhile you can extend cppCMS functionalities and write your own framework arround it.

wt was a good idea design, but somehow not that suitable.

ZeroCool
  • 1,490
  • 4
  • 19
  • 33
1

If you are exploring Python frameworks (based on the excepted answer I think you are) I think you really owe it to yourself to check out CherryPy. When you write CherryPy apps, you really are just writing Python apps. The framework gets out of your way in a real hurry. Your free to choose your own templating, ORM (if you choose to use ORM), etc. Seriously, take 10 or 20 minutes and give it a look.

Shaun
  • 3,928
  • 22
  • 21
0

The only reason you might want to use C++ over Python is when speed is paramount.

If this is going to be your first web-app, you'll probably be ok with just Python, and your development speed will be orders of magnitude better than with CPP.

Django's templating language is far from powerless, to me it actually seems very pythonic. You actually can write pure python in a template(although this is generally not recommended).

Even better, it's possible to replace Django's templating system with the one you like. My personal favourite language for this is HAML.

Here's some data on this: Is there a HAML implementation for use with Python and Django

Community
  • 1
  • 1
x10
  • 3,820
  • 1
  • 24
  • 32
  • You can't write pure Python code in Django's (default) templating language. (I don't see this as a limitation, though.) – mipadi Aug 17 '09 at 19:53
  • 3
    "The only reason you might want to use C++ over Python is when speed is paramount." *Another reason*: avoiding to create the situation in which every small project in your company is implemented in a different programming language, which in turn comes with a different IDE, standard library, custom written libraries, programming language quirks and limitations, library quirks, profilers, etc... – Dimitri C. Sep 14 '09 at 07:17
0

Having looked several ones, like django, pylos, web2py, wt. My recommendation is web2py. It's a python version of "ruby on rails" and easy to learn.