Вопрос

I have a problem. I am creating website and it is working well. But my boss told me that I shouldn't indent my codes because it can affect memory space because it reads the spaces or every indention in the code? Is this true? If yes can you provide me a reference for that so that I can defend myself. My boss show me some website in Japan that didn't indent their code and He ask me If indention is a program standard. If yes why some of the website in Japan didn't indent their code. It is all align left. I forgot some of the websites He showed me because it is in Japanese.

That's all thanks.

Here's the website that has no indention

http://www.dior.com/couture/home/ja_jp

Это было полезно?

Решение

For compiled code, it makes no difference whatsoever unless whitespace is significant in the language and means something that impacts memory usage.

Code transmitted over a network (HTML, CSS, JS, XML, etc.) can be made marginally smaller by removing spaces (in addition to compressing the output, which is considered a best practice). But this should never impact coding style and readability!

Whitespace removal can be done automatically when the page is served. This will actually increase the load on the server slightly (CPU, possibly memory), not reduce it. If the bandwidth savings are worthwhile (doubtful, if compression is enabled), it is an acceptable trade.

This answer shows the savings (or lack thereof) achieved by removing whitespace.

But my boss told me that I shouldn't indent my codes because it can affect memory space because it reads the spaces or every indention in the code?

"It" could refer to the web server sending the content or the browser reading the content.

  • Server: must send bytes of data from disk/memory in response to a request. So yes, extra whitespace may take a trivial amount more memory if the data is buffered and/or cached.

  • Browser: the browser can discard whitespace it doesn't need. It may never use any memory at all for those extra bytes of whitespace.

So (to be generous) your boss is right, but he is focused on the wrong thing. The savings (if at all) is measured in bytes and nanoseconds.

  • There are many, many other things that can be optimized first and will yield much more substantial benefits.

  • Hurting developer productivity is expensive. People indent code to make it more readable, and lack of readability equals lost productivity.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top