Spaces in equal characters

I'm just wondering if there is a performance difference using spaces before and after equal characters. Like these two pieces of code.

first

int i = 0; 

second

 int i=0; 

I am using the first one, but my friend who is studying html / javascript told me that my coding is inefficient. Is this true in html / javascript? And is this a huge performance hit? Will it also be the same in C ++ / C # and other programming languages? And about the indentation, he said that 3 spaces are better than a tab. But I already encoded the code. So I just want to know if he is right.

+5
source share
2 answers

Your friend is a little mistaken.

Additional gaps in the code will have a slight difference in the size of the JS file, which can slightly affect the download speed, although I would be surprised if it were noticeable or significant.

Additional spaces are unlikely to have a significant time difference for file analysis.

After analyzing the file, extra spaces will not matter at all in the speed of execution, since they are not part of the analyzed code.


If you really want to optimize your download or parsing speed, the way to do this is to write your code in the most readable way that you can best support, and then use the minimizer for the deployed code, and this is the standard practice of many websites. This will give you the best of both worlds - supported, readable code and minimum deployed size.

The minimizer removes all unnecessary intervals, reduces variable names, deletes comments, collapses lines, etc. .... all of them are designed to make the deployed code as small as possible without changing the code value during code execution.


C ++ is a compiled language. Thus, only the compiler used by the developer sees extra spaces (the same with comments). These spaces disappeared after the code was compiled into native code, which is the end user and runs. Thus, problems with spaces between elements in a line are simply not applicable at all for C ++.

Javascript is an interpreted language. This means that the source code is loaded into the browser, and then the browser parses the code during execution in some form of code of the operation that the interpreter can perform. Spaces in Javascript will be part of the loaded code (unless you use the minimizer to remove them), but after parsing the code, these extra spaces are not part of the code's performance at runtime. Thus, spaces can have little effect on load time and possibly even less impact on parsing time (although I assume this is unlikely to be measurable or significant). As I said above, a way to optimize this for Javascript is to use spaces to increase readability in the source code, and then to minimize the deployed file size, a minimizer over the code is run to create the deployed version of the code. This preserves maximum readability and minimizes download size.

+7
source

In productivity it is a little (javascript) - is not present (C #, C ++, Java). In compiled languages, in particular, the source code is compiled into the same machine code.

Using spaces instead of tabs might be a good idea, but not because of performance. Rather, if you are not careful, using tabs can lead to the appearance of a β€œtab rot”, where in some places there are spaces and spaces, and the indentation of the source code depends on the settings of your tab, which makes it difficult to read.

+2
source

All Articles