Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Yeah, node.js, that's true... But that's when JS is running on the server. Normally, in most cases, JS is running on the client side inside the web browser. And when you're inside the web browser, you cannot access the local file system.

Of course, in Windows, there is a way to read/write files with JavaScript using the FileSystemObject. So, I am well aware that JavaScript can be used to access the file system BUT NOT when you run it within a web browser!

(Pros: If you want to read the directory structure or open files from a NTFS file system, you may notice that JavaScript automatically reads file and folder names in Unicode format, which is neat! In perl, working with special characters in file names in Windows is a pain.

Cons: If you find yourself using JavaScript to work with files, you'll realize that the only way to read a file is to read the ENTIRE file, which is kind of dumb. Sometimes you don't want to read the entire file into memory, but JavaScript gives you no other option.)

The vec() function in perl allows a programmer to modify one character of a giant string by overwriting the string. Example: vec($a, 20000, 8) = 32; In perl, this operation is extremely fast, because all you do is modify one byte in the memory.

But in JavaScript, if you have a very long string and want to replace the 20000th character, you would have to use substring() function to cut the string into two parts and then join the parts together with a space character in the middle.

In other words, in the background, the JavaScript interpreter makes a copy of your entire string. And then from this copy, it creates another copy which contains the new modified character. So, instead of just replacing ONE character in the memory, it ends up copying the entire string twice. From a performance perspective, this is very-very poor design. And it's all because JavaScript does not have a vec() function. For this reason, JavaScript is like a baby toy.

When programmers MUST overwrite a character of a long string quickly, they usually split the string into an array, and that way they can manipulate the individual characters. And when they are done editing, they can join the array into a string. Fortunately, array operations are extremely fast in JavaScript, so this works pretty well. Except, from a resource management perspective, this isn't pretty, because JavaScript uses 22 bytes in the memory to store one element of an array. So, if you have a string that is 100,000 bytes long, and you split it into an array. It will then take up an additional 2 megabytes of memory. So, you wanted to modify one byte, and you ended up writing 2 million bytes to memory. Only because you wanted to change ONE byte in a string.

That's why they say, if JavaScript was a car, it would be a big version of Little Tikes toy car.


In reply to Re^6: Other similar communities you use? by harangzsolt33
in thread Other similar communities you use? by SkinBlues

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2024-04-18 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found