Categories
STATIC WEBSITES TUTORIALS

Advantages And Disadvantages Of Static Vs Dynamic Websites

Static websites are gaining popularity these days. A static website can be built using static website generators such as Jekyll (Ruby), Next (Javascript), Hugo (GO), Pelican (Python) etc. But very few people understand the benefits and disadvantages of using a static website. This article will try to explain this in a way that should hopefully make it easy for someone looking to decide between static website vs dynamic website for their purposes.

What is a static website?

Most of the websites we use these days are often dynamic websites. These dynamic websites have databases through which the content of a webpage is generated on the server dynamically and then sent to the user’s browser. Advantage of this is that each of the users get customized contents specific to them that are different from what would be delivered to other users. An example of this can be Facebook homepage of a user who get to see the posts from his friends and network. Google search result page is another example of a dynamic page that varies from person to person for the same query based on his browsing history.

Contrary to this, a static website is usually made up of static content (mostly using only HTML & CSS) that are already stored as complete files on the server. Thus, each of the users who request a particular webpage from this server will always receive the same content. Usually, these webpages are pre-built and stored on a file server and this file as a whole is then just sent back to the user’s browser when requested.

Advantages Of A Static Website

  • Fast: As these websites serve prebuilt HTML webpages, they are extremely fast.
  • Secure: As these websites do not possess a database but just a set of files served from a simple web based file server, there are no security threats seen that comes with using a database.
  • Cheap: The cost of hosting a static website is in pennies compared to a dynamic website as it just needs a simple web enabled file server.

Disadvantages Of A Static Website

  • As the contents are static and created in advance, no dynamic contents can be added to the web page.
  • User interactivity is limited due to the static nature of the website.
  • Usually static websites lack components such as comments, user login, recommendation engine, real time notifications etc. However, these can still be added through some 3rd party external services.
  • Programming knowledge is required to work with static websites. As we need to use static website generator tools that are quite technical in nature, users who wish to use static websites should be technically capable.
  • Content Management Systems (CMS) are usually missing in static websites. However there does exist some 3rd party CMS services such as Contentful that can overcome this issue.
  • Each time a new article is to be added, the static website generator builds the entire website and redeploy to the web server. This can be time consuming and can also be prone to unforeseen technical errors.
  • Not suitable for a large website with thousands of articles as updating such static website can be extremely slow.

Conclusion

Each of these static vs dynamic websites brings about their own set of advantages and challenges. So a decision as to which one is better for you completely boils down to how familiar you are with programming to work with static website generators, your website content types and its requirements.

If you are just looking for simple blog type of website to operate at a cheap cost, you can definitely opt for a static website. On the other hand, if you are looking to create a website having thousands of web pages or contents that are to be customized specific to each user, then dynamic website is the way to go!

Categories
PYTHON TUTORIALS

Difference between expression and statement in Python

A Python expression can be defined as any element in our program that evaluates to some value. Well, what does this mean? To understand it better, let us fire up our Python interpreter and take a deep dive into this topic on Python expressions with these examples.

Once in our python interpreter, let us type the following command:

Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "copyright", "credits" or "license()" for more information.
>>> 4
4
>>> 

We can see that by simply entering the number ‘4’ into our Python interpreter, it was accepted and evaluated to be of a value of integer 4. Hence, we can say that the input ‘4’ we entered is a type of expression.

Similarly, if we input the command ‘4 + 1’ to the Python interpreter:

Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "copyright", "credits" or "license()" for more information.
>>> 4
4
>>> 4 + 1
5
>>>

Our interpreter goes ahead and computes a value of 4 from this and results in a value of 5. Here too, the input ‘4+1’ can be called an expression as it resulted in a value of 5.

Similarly, if we enter this code to the Python interpreter we get,

Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "copyright", "credits" or "license()" for more information.
>>> 4
4
>>> 4 + 1
5
>>> "Hello" + "World"
'HelloWorld'
>>> 

This too shows that irrespective of the data type used (string in this case as opposed to integers in the earlier examples), a Python expression results in the evaluation of the data (“Hello” and “World”) to a final value (“HelloWorld”). Thus “Hello” + “World” is also a Python expression.

On the other hand, if we take a look at this example:

Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "copyright", "credits" or "license()" for more information.
>>> 4
4
>>> 4 + 1
5
>>> "Hello" + "World"
'HelloWorld'
>>> result = "Hello" + "World"
>>> result
'HelloWorld'
>>> 

Here we are assigning the final evaluated expression value to another variable ‘result’. This type of command where a value is assigned to a variable is called a Python Statement.

So in other words, we can see that a Python statement is made up of one or more Python expressions.

Expression Vs Statement

  • Expression
    • Expressions always returns a value
    • Functions are also expressions. Even a non returning function will still return None value, so it is an expression.
    • Can print the result value
    • Examples Of Python Expressions: “Hello” + “World”, 4 + 5 etc.
  • Statement
    • A statement never returns a value
    • Cannot print any result
    • Examples Of Python Statements: Assignment statements, conditional branching, loops, classes, import, def, try, except, pass, del etc

Summary

In simpler terms, we can say that anything that evaluates to something is a Python expression, while on the other hand, anything that does something is a Python statement. Curious to learn further? Follow our other articles in this blog to know more!