Large

Simplepedia

By Grant Stavely Last update Jul 17, 2009 — Installed 14,579 times. Daily Installs: 29, 15, 15, 10, 15, 23, 24, 17, 19, 20, 31, 22, 20, 17, 21, 24, 14, 18, 12, 17, 15, 16, 26, 26, 7, 48, 5, 16, 27, 12, 16

Fonts and lint

Subscribe to Fonts and lint 5 posts, 2 voices

iaindalton User

Linux comes with a bitmap font called Helvetica. It looks terrible; nothing like the Helvetica that comes with Mac OS, except at large sizes. I'd change the if...else to a switch and have a few simple options: 'sans-serif', 'serif', and 'default', which would use whatever the wiki has set default.

Also, why all the empty catch statements? I tried removing them all and only got a couple "foo is null" warnings which I fixed by wrapping the appropriate code in if (x !== null) {...}. (I use === and !== because they're more efficient than == and != and don't do that weird type coercion.)

 
Grant Stavely Script's Author

Thanks - now that the style declarations are inline with the script, they can just directly reference the font name, not call a file name.

This project is a way for me to learn javascript, so this advice is really helpful. Most of my informal coding is in perl, which has no switch statement, and converts types on the fly.

The catch statements are for exception handling under development. Now that I've dabbled in this bit of js, I can go back and tighten up my style.

 
iaindalton User

Interesting---You're trying to learn JavaScript by writing in GreaseMonkey, and I'm trying to learn GreaseMonkey by reading some scripts (haven't written anything yet) :-)

For learning JS, check out Douglas Crockford's articles[0] which explain how to avoid some of JavaScript's pitfalls. Also nice is JSLint[1] which warns about things that may have unpredictable results. For example, JS doesn't have block scope, only function scope, so any var declaration is 'hoisted' to the top of the function, even if you typed it in a loop or conditional. So having var i = 0; in several for loops within the same function (or outside any function) is an error: put var i; before the loop and i = 0; in the loop.

[0]: http://www.crockford.com/javascript/
[1]: http://www.jslint.com/

 
Grant Stavely Script's Author

Very interesting scope issues. I tend to cargo cult a lot when self-teaching and eventually go through entire rewrites (and more rewrites) as I grow.

 
Grant Stavely Script's Author
SafariMacintosh

On the Linux and Windows font front - what are you all using? It looks like FreeSans is the closest common Linux font?

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel