Closed Thread Icon

Topic awaiting preservation: Unreadable code anyone? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=23355" title="Pages that link to Topic awaiting preservation: Unreadable code anyone? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Unreadable code anyone? <span class="small">(Page 1 of 1)</span>\

 
TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 09-19-2004 15:56

I've noticed that some people (none at this forum that I know of lol) always write their code
without any whitespacing like tabs or normal spaces. This makes their code really hard to read.
I know it optimizes the download speed but if people want me to help them with their scripts,
they could atleast send me a readable version.

Therefor I wrote this little script:
http://www.geocities.com/therulers3000/filer/jscf.htm

It should not alter your scripts in any way except for adding semicolons at the end of lines
and adding whitespaces for better readabiliy.

I have no way of testing this on every kind of script so I ask for your help.
Simply paste your scripts in the input field, click "Format Code" and replace the old
script with the new one from the output box and test it.
Don't forget to make a backup of your files in case you find an error!

If you find a script the formatter can't handle, try to isolate the problem
or send me a copy of it.
I've had some problems with regular expressions before but that should be solved now.

If you have any suggestions/ideas on how the formatted code should look like, please post them as well.

Thank you in advance to anyone who's willing to help.

/TwoD

(Edited by TwoD on 09-19-2004 15:57)

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 09-22-2004 09:31

Nobody who wants to help?
It would be greatly appreciated.

/TwoD

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 09-22-2004 10:24

well... I've written a pretty printer or two in the past, and if they're actually using the language's backus-naur form definition, they're pretty reliable.
Sorry, don't have any javascript handy to test your's with.
The site could need a sentence or two of explanaiton of what it actually does, though.

so long,

->Tyberius Prime

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 09-22-2004 11:39

Good idea, should have thought about that myself....
Was in a hurry to upload it so I guess I forgot.
Didn't understand that backus-naur stuff so I can't say if it uses it or not

/TwoD

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 09-22-2004 12:04

Double post, ignore this.

(Edited by TwoD on 09-22-2004 12:12)

bsilby
Obsessive-Compulsive (I) Inmate

From: Christchurch
Insane since: Sep 2004

posted posted 09-23-2004 21:06

I've started compressing my code before putting it online. Of course, I keep an uncompressed copy here. I've found that removing whitespace makes the file about 10% smaller. I also remember reading that it improves script running speed, which is important for my use.

I am thinking about remapping objects and renaming variables too. There is a useful software that does this called w3compiler. It can reduce the file size by up to 30%. The only reason I'm not doing this now is because in one of my tests, it screwed up one of the variable renames and caused a script error.

Does anyone know if remapping objects can make a script run faster?

BRENT SILBY
www.def-logic.com
Neo-Arcade Videogames

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 09-24-2004 23:25

I don't know exactly what you mean by "remapping" objects but I'm sure renaming variables to shorter names will improve download speeds. But I'm not sure it would improve execution speed, maybe slightly but probably not enough to make a difference.

Could you link to this w3compiler? I've tried several "optimizers" but they all had drawbacks, and most of them required a semicolon as a line termination. (Which I rarely use)

/TwoD

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 09-25-2004 17:50

I suspect you mean pulling variables into local scope
(like wlh = window.location.href).
This should - in theory - indeed be faster if you're using the object variable multiple times, since the local lookup usually is faster than an object lookup.

bsilby
Obsessive-Compulsive (I) Inmate

From: Christchurch
Insane since: Sep 2004

posted posted 09-26-2004 01:03

Hi TwoD,
The w3compiler is produced by port80. The link is www.w3compiler.com. Its the best code optimizer I've found.

Hi Tyberius,
Yes, I was refering to remapping in the way you mention. Eg d=document.getElementById. What sort of speed difference do you think this would make. I've played with it, but don't really notice any visible difference. But I'm thinking it could be worthwhile for people who visit my site with slow computers. And if nothing else, it really shrinks the code size alot.

Brent.

BRENT SILBY
www.def-logic.com
Neo-Arcade Videogames

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 09-26-2004 09:37

Well... I'm no expert. I believe to have heard that Firefox is rather slow with object look ups, but it might have been the other way around.
Either way it won't matter if you're not doing an awfull lot of them. They're still 'cheap'.

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 09-26-2004 22:07

I wonder if remapping this way really pulls the object into local scope, or just gives it a local handle... no way to tell is there?
Thanks for the link Brent.
Too bad it isn't free... not sure I would trust it entierly though. I usually try to write my important code as optimized I can from the beginning and then carefully go through it to make sure there are no potential errors/performance leaks.
That's why I wrote my own white-space remover/adder, so I can keep my code 100% unchanged.

/TwoD

bsilby
Obsessive-Compulsive (I) Inmate

From: Christchurch
Insane since: Sep 2004

posted posted 09-27-2004 01:39

I've had no problem with the optimizer removing whitespace. I don't let it rename variables and functions because its too risky. I tried it once, and it seemed to be fine but then I discovered an error. It had renamed all the variables and functions in the code fine, but one of my document.writes contained an a href to a function. It did not rename the function call in the document.write, but it did rename the function.

That's the only problem I've found with it.

BRENT SILBY
www.def-logic.com
Neo-Arcade Videogames

« BackwardsOnwards »

Show Forum Drop Down Menu