This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 30 Mar 2009 05:40:25 pm    Post subject:

ok instead of writing to http://www.unitedti.org/index.php?showtopic=8566

I though more appropriate to make this topic. So the other doesn't look like questions about web developing instead of the site itself.

java script:
what is better:
strX = compact(strX)
strX = strX.split(" ")
strX = strX.length

or

strX = compact(strX).split(" ").length;

What I see is that the first is easier to read... But the second can be more optimal for speed/size? What compensates more for web developing?

Also instead of using the php include to a header we could use a java script: document.write("all the header stuff here")
But php still looks much cleaner.

Thanks in advance.
PS: could you indicate a nice forum about general web development? I found many but only after visiting it some time we got the feeling of if it is nice or not.


Last edited by Guest on 30 Mar 2009 05:41:08 pm; edited 1 time in total
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 30 Mar 2009 05:50:06 pm    Post subject:

It is possible that website users may not have javascript, either because they are using an old browser or because they have it turned off to pop-up ads. Therefore, I generally use javascript for effects that are nice but not essential to use the site. As you said, php is much better for including essential content like headers.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 30 Mar 2009 11:28:10 pm    Post subject:

It would be somewhat ridiculous if there were anything but the slightest difference in speed between those two pieces of code: the size difference is exactly the difference in the number of characters, since javascript isn't compiled or anything, and is also mostly irrelevant except for HUGE blocks of javascript code that in my opinion shouldn't exist anyway except in rare cases.

The difference in readability is an opinion (I think the second is more readable, myself), but in this case you're writing the code for yourself to read, so pick whichever one looks best to you.
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 31 Mar 2009 03:58:33 am    Post subject:

magicdanw wrote:
It is possible that website users may not have javascript, either because they are using an old browser or because they have it turned off to pop-up ads. Therefore, I generally use javascript for effects that are nice but not essential to use the site. As you said, php is much better for including essential content like headers.
Javascript will be a secondary goal. ;)

And DarkLine, maybe the second is as readable as the first... Depends on persons though.


As other questions arise I will post here.
EDIT: have new ones:

- How to replace spaces without replacing newlines? Because \s also indicates spaces.
I couldn't find a simple way in: http://www.w3schools.com/jsref/jsref_obj_regexp.asp
(and it says that is a complete reference...) And if there is a way without looping for
Nevermind just use /x20...
Even better (facepalm...): ' '

Also I don't get why /r acts as a newline? How common is it? What is the origin? Linux and unix maybe because it uses a different newline.


Last edited by Guest on 13 Apr 2009 08:20:11 am; edited 1 time in total
Back to top
benryves


Active Member


Joined: 23 Feb 2006
Posts: 564

Posted: 31 Mar 2009 04:50:28 am    Post subject:

Windows (and the Internet, certainly HTTP and email) use CRLF ("\r\n" in C) to indicate newlines, UNIX-derived operating systems use LF and classic Mac OS and the BBC Micro (amongst others) use CR.

Never use document.write(); manipulate the DOM to add, edit or remove elements on the page. The same applies to innerHTML: try not to use it if possible. I recommend using a good JavaScript framework (such as MooTools) to make your life easier.
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement