Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. Javascript is bad.
  2.  
  3.  
  4.  
  5. Google "javascript syntax error" and you'll find a lot of useful information.
  6.  
  7. I just wanted to share some alternatives I have found over the past few years, and explain why I do what I do.
  8.  
  9. Let's get started:
  10.  
  11. CSS Preprocessors:
  12.  
  13. One alternative to the silly Javascript error is to use CSS preprocessors such as Sass, Less or Stylus. Some argue that the advantages of Sass come from its more powerful syntax and add-ons built in the preprocessor itself, and in fact one of the main advantages Sass has over Javascript is that it is a compiled language and therefore compiling gives you a more comprehensive syntax error as the code is run on the server and not the client. As an example (unfortunately I don't have time to write a nice Sass tutorial for this to be clear so I'll use the incorrect syntax here for now):
  14.  
  15. foo = $text . string ( '*' ) !== [] !== '' ? 'foo' : ''
  16.  
  17. You could argue against this with the following argument. By the time you have all of your Sass rules, as they compile they might add script logic that tries to pass them through an array too, which has never happened to me so I've never seen this happen. I also won't mention that lots of people use mixins to hide various libraries written in C or Flash. I think you have the whole argument for using Sass.
  18.  
  19. One advantage of this syntax is that you can use everything you need in a single file, which saves you a lot of time. Just remember if you use more than a single preprocessor, or complex mixins, you do need to be aware of nesting, which will require debugging in the terminal. It's just a compromise you have to make.
  20.  
  21. Lists:
  22.  
  23. Here's a great web app which gives you the step by step walkthrough and pros/cons of using lists and structures in your code: http://voices.cc/2010/07/29/abusing-lists-in-django-django-of-course-youre-using.html
  24.  
  25. I recently learned about Bulletproof when I was programming a django site, it's more a debugging tool in django which deals with hitting fatal errors rather than js errors, but it also enables you to check very hard that all other errors are also true. It gives you a little pro/con list, where the arguments for bullets seem to outweigh with pro's.
  26.  
  27. The whole thing is an html templating framework.
  28.  
  29. You can find out more on its Github page:
  30.  
  31. https://github.com/bulletproofweb/bulletproof/wiki
  32.  
  33. Generators:
  34.  
  35. Another plugin for Django and some info on Generators: http://code.google.com/p/django-generators/wiki
  36.  
  37. Micro Templating:
  38.  
  39. Micro Templating is not the same as proper python or Javascript functions, but rather projects in javascript and javascript style libraries such as gulp, grunt or hot-reload.
  40.  
  41. Gulp is a package manager for task runners, making it easy to do all sorts of stuff, such as firebase development with Gulp.
  42.  
  43. Grunt is an amazing task runner/build system for developing single page applications. It also comes with a ton of plugins which make it very versatile in terms of tasks.
  44.  
  45. Hot-reload makes it trivial to switch between your client and server whenever you want.
  46.  
  47. You can find out more about generators here: http://facebook.github.io/gativec/
  48.  
  49. Code Browser or Code Watcher
  50.  
  51. Finally you can install a code browser on your pc so you can trace your code.
  52.  
  53. This is a really great command line web application, it's written in Python and it really does what it should do (show you what's going on).
  54.  
  55. The by far the most powerful feature of the app is the ability to force reload the code on a given url, not only that you can track your errors by hitting the tilde (~) key (ie., click debugger). This page also has tons of documentation on all of it's features and it's different ways of using it.
  56.  
  57. On top of this, if you try to make a typo, you don't even need to refresh the page, you can look it up in the code browser for a more detailed explanation.
  58.  
  59. There is a good tutorial here:
  60.  
  61. http://www.blog.wenzio.com/tutorials/fast-make-and-debug-ingesting/
  62.  
  63. Code Watcher is very straight forward, but it also has a way of checking templates and code changes during development.
  64.  
  65. The thing is, sometimes the first line of code you wrote isn't what looks great in the end, so as you write more you're going to get better at code watching.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement