Project

General

Profile

Blog Examples and Wt Best Practices

Added by I. Lazaridis over 8 years ago

I'm using the blog-example in order to make a teach-in to wt and to simplify it a bit, thus it becomes a bit easier for people (evaluators, developers, users, ...) to take a look at wt.

https://github.com/lazaridis-com/blog-wt

Is it possible that the blog-wt code was not written to showcase wt best practices?


Replies (9)

RE: Blog Examples and Wt Best Practices - Added by Koen Deforche over 8 years ago

Hey,

The real motivation for the blog example was to have a blog on the wt homepage, and to verify how practical Wt::Dbo would be in an actual application.

All in all, I do not think that the blog example is a bad example of a Wt application, although it was written in one go, and never revisited for architecture choices. So I wouldn't be surprised if things can be simplified and improved, but nevertheless I am curious what you had in mind?

Regards,

koen

RE: Blog Examples and Wt Best Practices - Added by I. Lazaridis over 8 years ago

ok, I understand.

I had in mind to change things like "readability", making code self-explaining, less "cryptic", making code resusable (= a bit of decoupling), a bit of documenting.

So that one can take this application, and have a nice intro to wt/dbo and a template for an own app.

This is basically what I do for myself, but by investing more time, it becomes usable for others, too.

As I plan to use Cmake for personal projects, I like to simplify/abstract/OO-Normalize the whole cmake process, too, starting again with simplification/documentation:

https://github.com/lazaridis-com/blog-wt/blob/master/CMakeLists.txt

I'll have some more info tomorrow, as I'll most possibly spend the night on this code.

RE: Blog Examples and Wt Best Practices - Added by I. Lazaridis over 8 years ago

I. Lazaridis wrote:

[...]

I'll have some more info tomorrow, as I'll most possibly spend the night on this code.

Well, the blog application is definitely not the one to start with. It needs some documentation/rework from the author itself (or from someone with deeper knowledge of wt).

Just one example is this:

https://github.com/kdeforche/wt/blob/7b836d9dc4220cbc2f58276654b46961d38a5931/examples/blog/model/Comment.C#L44

I would not expect such code in example code (that should be a reusable library call).

Another problem is the BlogView.C, which seems a bit overloaded with code. The missing documentation makes it quite impossible to understand quickly what is going on.

I've managed to simplify the main file:

https://github.com/lazaridis-com/blog-wt/blob/master/src/Blog.C

In this high-level code, one should not be forced to use "boost::bind(&createApplication, _1, blogDb)". This is just too much (this could be simplified, by changing the API call).

in this blog example, possibly the use of WtTemplate should be demonstrated (if applicable, with an external template file).

-

For the case that blog-wt cannot be simplified enough, is there any other, simpler example which combines dbo and some widgets?

RE: Blog Examples and Wt Best Practices - Added by Koen Deforche over 8 years ago

Hey,

W.r.t. Comment::setText(), I don't think that is terribly bad (beyond what is said there in comment): it's text processing. Text processing isn't part of Wt; that's just C. We could move it to some function in the same or a different file. The text processing that happens there isn't anything generic either. I wouldn't know what 'library function' you hint at because this is a very specific feature of the blog.

W.r.t. BlogView, yes, this file grew with functionality over the years, and could easily be split up since most things are self-contained.

As to the simplifications in blog.C: I agree with some of the feature requests that this depends on; but I think that importing from namespaces actually makes things harder to understand. We've actually moved away from importing the Wt namespace in examples to make them easier to understand (even if they are then a bit harder to read).

I don't understand the comment about boost::bind(): how could the API be changed to avoid this?

And the blog example does show the use of WTemplate in various places?

Regards,

koen

RE: Blog Examples and Wt Best Practices - Added by I. Lazaridis over 8 years ago

Koen Deforche wrote:

W.r.t. Comment::setText()

W.r.t. BlogView

ok

As to the simplifications in blog.C: I agree with some of the feature requests that this depends on; but I think that importing from namespaces actually makes things harder to understand.

We've actually moved away from importing the Wt namespace in examples to make them easier to understand (even if they are then a bit harder to read).

I understand your point of view.

Readability should be compared to other (non C) web frameworks, too, and "with the eyes" of a newcomer (not long-year experts, like you). Someone who is e.g. used to ruby code will get simply a shock looking at the code, backing immediately off.

I don't understand the comment about boost::bind(): how could the API be changed to avoid this?

It starts with saying: "I want this, thus it's simpler for users". Then it's either solvable, or not. The ideal thing would be something like:

server.add(MyWtApplication, "/mypath")

(I'll open a topic on this, as this interests me technically, too)

And the blog example does show the use of WTemplate in various places?

Don't forget: you are an expert with this system, I am not. I don't see things as obvious as you - and that's true for any newcomer.

-

I've mentioned several issues here, not to criticize, but to get a better picture of this example and wt in general.

You've possibly overseen my most important question:

"For the case that blog-wt cannot be simplified enough, is there any other, simpler example which combines dbo and some widgets?"

RE: Blog Examples and Wt Best Practices - Added by Alan Jesser over 8 years ago

I've used a mix of of the auth and blog examples to get a deeper understanding of the DBO. http://www.webtoolkit.eu/wt/doc/tutorial/dbo.html is also a good example. The later explains more about what is happening while the former 2 show it's use in a complete example.

I would like to see what you come up with because I'm in the process of writing my own blog widget. I plan to make it more like what you see with common blogging sites now. Also, since TinyMCE4 support is nearly complete I'm working with that as my text editor instead of how the example does it.

RE: Blog Examples and Wt Best Practices - Added by I. Lazaridis over 8 years ago

Alan Jesser wrote:

I've used a mix of of the auth and blog examples to get a deeper understanding of the DBO. http://www.webtoolkit.eu/wt/doc/tutorial/dbo.html is also a good example. The later explains more about what is happening while the former 2 show it's use in a complete example.

I meant more a ready-to-go example application with everything in it.

I would like to see what you come up with because I'm in the process of writing my own blog widget. I plan to make it more like what you see with common blogging sites now. Also, since TinyMCE4 support is nearly complete I'm working with that as my text editor instead of how the example does it.

Sounds very interesting (like modernizing wt), please provide a repo link once you start it!

RE: Blog Examples and Wt Best Practices - Added by Koen Deforche over 8 years ago

I. Lazaridis wrote:

> We've actually moved away from importing the Wt namespace in examples to make them easier to understand (even if they are then a bit harder to read).

I understand your point of view.

Readability should be compared to other (non C) web frameworks, too, and "with the eyes" of a newcomer (not long-year experts, like you). Someone who is e.g. used to ruby code will get simply a shock looking at the code, backing immediately off.

I understand that. But we should not only make it look easy, it should also be actually easy, and stripping of namespaces from examples turns out to make actual 'copy/pasting' harder and slows down comprehension.

> I don't understand the comment about boost::bind(): how could the API be changed to avoid this?

It starts with saying: "I want this, thus it's simpler for users". Then it's either solvable, or not. The ideal thing would be something like:

server.add(MyWtApplication, "/mypath")

(I'll open a topic on this, as this interests me technically, too)

And MyWtApplication is a class or a function?

The use of boost::bind() is usually not necessary, unless you really want to pass some variable to the bound function, as in this case. Just take a look at the other examples. But actually, the use of WServer itself is already optional and advanced. The minimum skeleton for a working application is the hello world example. This is what a "ruby user" should look at first.

"For the case that blog-wt cannot be simplified enough, is there any other, simpler example which combines dbo and some widgets?"

There's also the hangman example.

Regards,

koen

RE: Blog Examples and Wt Best Practices - Added by I. Lazaridis over 8 years ago

Koen Deforche wrote:

I. Lazaridis wrote:

> > We've actually moved away from importing the Wt namespace in examples to make them easier to understand (even if

[...]

See #2794

> > I don't understand the comment about boost::bind(): how could the API be changed to avoid this?

[...]

See #2754

The use of boost::bind() is usually not necessary, unless you really want to pass some variable to the bound function, as [...]

The minimum skeleton for a working application is the hello world example. This is what a "ruby user" should look at first.

See #2795

> "For the case that blog-wt cannot be simplified enough, is there any other, simpler example which combines dbo and some widgets?"

There's also the hangman example.

"Many basic concepts of Wt, including also Wt::Auth and Wt::Dbo."

Ok, looked at the code, it seems cleaner than that from the blog!

See #2796

    (1-9/9)