some thoughts on web-development in C++/CppCMS
overview of CppCMS
Part 2 (of 2)
example application (show, discuss some code)
People say: 'Why can't I write my web-pages in C++?'.
One: You can, two: Why would you want to? That's not what its specialized for. There are a lots of languages that are specialized for that job.
Bjarne Stroustrup at CurryOn 2015 (video here)
Performance (embedded systems)
"Make the world a greener and better place"
Performance !!!
use modern C++ as primary language
Rapid prototyping?
short time-to-market periods ...
my experience: web-apps often start as small app/prototype and change fast ...
... to grow big and have performance problems! (actually a "pro")
extremely powerful for:
borrowed from here /more info
do not "exegerate" (choose wisely how much and where 'to C++'):
You want interactive and efficient GUI - use client side javascript technology and combine it with solid backed - making it "integrated" is just wrong.
Artynom Beilis (cppCMS core dev)
Hello World (source)
class hello : public cppcms::application {
public:
hello(cppcms::service &srv) :
cppcms::application(srv)
{
}
virtual void main(std::string url);
};
Declaration
void hello::main(std::string /*url*/)
{
response().out() <<
"<html>\n"
"<body>\n"
" <h1>Hello C++ User Group NRW</h1>\n"
"</body>\n"
"</html>\n";
}
Definition
int main(int argc,char ** argv)
{
try {
cppcms::service srv(argc,argv);
srv.applications_pool().mount(cppcms::applications_factory<hello>());
srv.run();
}
catch(std::exception const &e) {
std::cerr<<e.what()<<std::endl;
}
}
main entry point
{
"service" : {
"api" : "http",
"port" : 8080
},
"http" : {
"script" : "/hello"
}
}
configuration (config.js)
run with:
./hello -c config.js
well documented ( API)
allows to build large yet maintainable and scaleable applications (OOP)
sophisticated templating & caching mechanism
... with performance and security in mind
wide spread usage
integrated JSON handling
templates: "V in MVC"
my example code will not use templates
even more (benchmarks, CppCMS missing):
even more frameworks (with benchmarks, CppCMS missing):
inspired by TodoMVC
very simple app:
kata-like specs (js):
it("adds a new todo to the list of todos at the root url", function(){
var getAfterPost = postRoot({title:"walk the dog"}).then(getRoot);
return getAfterPost.then(function(todosFromGet){
expect(todosFromGet).to.have.length(1);
expect(todosFromGet[0]).to.have.property("title","walk the dog");
});
});
There is no implementation in C++
but almost in every other language!
The C++ language is far from being a popular Web development language for many reasons: lack of appropriate tools, skills of developers, compilation requirements, slower to change pages and try out ideas, and many more.
I chose the following setup:
Thank's for your attention, so far.
Let's go over to part 2 and have a look on some code. Try out the app and discuss it.
Feedback very appreciated...