⬆️ ⬇️

Web technologies through the eyes of a C ++ programmer

A year ago, acquaintances asked me to make a website with dynamic content. Then I knew a little more about the Web than nothing, but it was interesting to try.



Under the impression of an inveterate C ++ programmer from the Web world, his own bikes, unusual solutions, resentment over and without. All emotions are in spoilers, so as not to burden the article.



I hope it will be interesting for Web developers to look at the attempts of C ++ nickname, and C ++ developers will learn something new for themselves.

')





Selection of server-side tools



Being in firm confidence that you should not hammer nails with ++, PHP was chosen as the main development language. The rest of the languages ​​have lost comparisons on support, the number of articles and manuals, popularity.

... what about garlic?
One friend said a long time ago that "PHP is learning in a day!". It is this lightness and has become the main factor of choice.


The operating system for development was chosen by Ubuntu 14.04, the PostgreSQL database.

... and what is not MySQL?
My acquaintance with MySQL always quite quickly ended with a complete demolition of MySQL and the installation of anything else. The reasons for this are more than enough:

  • MySQL does not support SQL well, and ignores what it does not support (for example, references to create table)
  • MySQL was slow until patches from Oracle
  • after patches from Oracle MySQL makes me fear like any Oracle product. Oracle products break in my hands at the most inopportune moment. For example, once BerkeleyDB recorded garbage in the database and did not notice this for a month, and after a month of work, the database was no longer recoverable.
  • MySQL significantly benefits PostgreSQL only in the speed of creating a new connection to the database. Not caching connections is bad form => there are almost no advantages




The web server was chosen nginx. Apache features would be redundant for a fairly simple project.

... and there were other reasons?
It was interesting to try the new nginx tool, which is full of positive reviews.





First disappointment



Putting PHP-fpm and writing “Hello world!” I was glad that everything was moving well, but then an article about the penetration test came across . From the article it became clear that the default PHP configuration is dangerous! After that, the day went on setting up PHP ... and in a month two more days. There is no firm conviction that everything is alright!



Very sad a lot of opportunities to shoot yourself in the leg in terms of security. But PHP is a language that was originally designed to work with the Web.



Client-side tools



After a dubious struggle with the configuration, it was decided to take a rest and estimate how the page should look. Informed about Bootstrap, I found a couple of page templates on it with not broken adaptive design, I chose a prettier one and began to customize it for the project.



CSS




Hands, coarsened from the brutal C ++, completely not suitable for working with the beautiful. It was extremely difficult to squeeze out anything worthwhile, the hours of painstaking work went into minimal correction of the design.



As a result, the following mechanism for working with design was developed:





Bootstrap


Bootstrap for CSS is like Boost for C ++. It’s hard to imagine how much effort goes away if you don’t use it. My insignificant CSS knowledge at that time was more than enough to start using it, customize it and even make a beautiful menu at the top of the page.

... is that a perfect match for your needs?
Not really. I wanted to hover on the menu drop-down submenu. Bootstrap did not have the necessary functionality, but as it turned out, adding it is extremely easy:



ul.nav li.dropdown:hover > ul.dropdown-menu { display: block; } .navbar .dropdown-menu { margin-top: 0px; } 




It was just as easy to make a bigger font:

 /* Making menue font bigger*/ .nav > li > a { font-size: 1.1em; } 


So I am very pleased with Bootstrap!





jQuery


jQuery is what javascript really should look like. Short function names, animation , easy access to and iteration over elements, abstraction over browser-specific things. Basics are understood in 15 minutes of reading the documentation.

... did everything fit perfectly?
Upset about the lack of frequently used things:

  • working with cookies (setCookie, getCookie)
  • a more advanced string class would be useful (startsWith, isLetter)


I had to make an auxiliary file with javascript and put my extensions in it.





Development



In the process of development, various problems and shortcomings of the selected tools and technologies began to manifest, faced with the lack of adequate implementations of basic things.



Oauth




The biggest problem was the authorization of users. It was decided to use third-party services for authorization, such as VKontakte, Twitter, Facebook, Yandex, MailRu, Odnoklassniki.



Suddenly it turned out that all known services see OAuth in their own way. The differences are not that very significant, but due to small details the development has turned into a real blood pressure !





At the same time, all services have error messages that are absolutely not informative , and debugging PHP code is a separate pleasure, which is described below. In addition, the answers from all the services come in their own format , in no way similar to the formats of other services.

... and what's wrong with Twitter?
It's absolutely wrong with Twitter! Some inadequate restrictions on the session, because of what can use it 1-2 users per day, and then, if they rarely click. After exceeding the limits, Twitter begins to behave like a schizophrenic in the spring:

  • returns OK, but does not authorize
  • does not return to the previous page due to constant redirects
  • breaks all the logic of the site due to the fact that the authorization is OK, but in fact is not OK and you need to redirect ... And from the redirected page it is impossible to return because of the constant non-deactivating redirect






Php


With PHP, everything is pretty good - language is like a language. However, after C ++ it was unusual to work with an interpreted language: errors that in C ++ are at the compilation stage in PHP are only on runtime. Realized that C ++ - corrupts , allowing less time to spend checking for typos.

... something you keep back!
There would be a lot less errors if new variables were created using a keyword (for example var as in javascript, or auto as in C ++ 11). Otherwise, any typo in the variable name becomes a new variable .





In PHP, the lack of a free debugger, the lack of a free development environment.

... because I bought and the problems were gone?
Nope I'm greedy! I remembered my youth with writing programs in notepad and debugging via printf .





Slide show


For the slideshow from the pictures used Backstretch plugin. But I had to make a text slideshow by the very fact that I wanted to look good on small screens. If you do through the pictures would have to do pictures for different screen resolutions, but it is a long time.



Therefore, it was decided to place the beautiful layout of the text on Booststrap, and just hide the pieces of text and show by timer.



Optimization


A draft version of one of the pages weighed a few megabytes. Loaded up stupor for a long time. Pagespeed came to the rescue with his own tips.



But the greatest help was provided by the site TinyPNG , which using black magic and quantization squeezes pictures several times without loss of quality.

... know the basics and consider yourself cool?
At first, I thought that I had discovered trivial things. However, after I went through a number of very well-known and popular resources with these tools, it turned out that very few people care about size . What can I say, Google itself is not as good as it could be.





Internet Explorer - nyashka!


I am absolutely serious. Internet Explorer is great! Of course, not as a browser for the user , but as a means of debugging the site. Of course, not as a debugger or style inspector.



Internet Explorer - displays the site with virtually no CSS extensions, it is very picky about markup and loads pages for an incredibly long time. These are all pluses ! On it, you can make sure that the site is quickly displayed, that unclosed tags have not accidentally crept in to javascript. In the end, you can see how the site looks in the worst case, and that the content is still readable.

...Seriously?
Yes.

... seriously seriously?
YES.







Results



Inexpressible sensations from touching a new world for me. The sensations are mostly positive, and the result of the work looks decent to my unassuming taste.

Source: https://habr.com/ru/post/250825/



All Articles