background preloader

Bonnes pratiques

Facebook Twitter

Erreur de chargement de la page - Vimperator. Programming's Dirtiest Little Secret. This is another one I've wanted to write forever. Man, I've tried a bunch of times. No ruck. Not Rucky. Once again I'm stuck feeling so strongly about something that I'm tripping over myself trying to get my point across. So! Once upon a time... ...in, uh, let's see... it was about 1982.

Once upon a time in '82, there was this completely hypothetical fictitious made-up dorky 12-year-old kid named Yeev Staigey, who was enduring his sophomore year at Paradise High School in Paradise, California. Boy, I could tell you all sorts of stories about little Yeev at that age. However, our story today concerns Yeev's need to take a, um, an... elective of some sort. These "electives" (which you could "elect" not to take, in which case they would "elect" not to graduate you) were the kinds of courses that put the "Red" in Red-Blooded American.

Yeev noticed that one of the electives, surely placed there by mistake, was Typing. So Yeev was pretty fortunate in getting a coach. Learning Licks Yowza. So! Home | The Anti-IF Campaign. The Photoshop Etiquette Manifesto for Web Designers. Signs of a poorly written jQuery plugin. So far with every single workshop I’ve given, both for advanced JavaScript and jQuery for Designers, this question (or some variation thereof) has come up: How do you know if the plugin is good to use? It’s always dependant on the problem they’re trying to solve, but in lieu of a better jQuery plugin ranking system, here’s a couple of tips that should raise a red flag.

Consider the following: $.fn.myplugin = function () { var me = $(this).each(function() { return $(this).bind('someEvent', function () { // does something }); }); return me;}; Although the code may be perfect once some event has run, most times you don’t have time to read through all the code carefully and you need to make a decision so you can move on to the actual problem you’re trying to solve. In the code above, there’s a number of red flags that have gone up for me, and I tend to look in this area of code first. The inline return $.fn.myplugin = function () { var me = $(this).each(fn); return me;}; Should be written as:

A Plugin Development Pattern. I've been developing jQuery plugins for quite a while now, and I've become rather comfortable with a particular style of plugin development for my scripts. This article is meant to share the pattern that I've found especially useful for plugin authoring. It assumes you already have an understanding of plugin development for jQuery; if you're a novice plugin author, please review the jQuery Authoring Guidelines first. There are a few requirements that I feel this pattern handles nicely: Claim only a single name in the jQuery namespace Accept an options argument to control plugin behavior Provide public access to default plugin settings Provide public access to secondary functions (as applicable) Keep private functions private Support the Metadata Plugin I'll cover these requirements one by one, and as we work through them we'll build a simple plugin which highlights text. Claim only a single name in the jQuery namespace This implies a single-plugin script.

JavaScript: Putting it All Together. Essential JavaScript Design Patterns For Beginners. I would like to thank Rebecca Murphey for inspiring me to open-source this mini-book and release it for free download and distribution - making knowledge both open and easily available is something we should all strive for where possible. I would also like to extend my thanks to the very talented Alex Sexton who was kind enough to be the technical reviewer for this publication.

I hope that it helps you learn more about design patterns and the usefulness of their application to JavaScript. Volume 2 of Essential JavaScript Design Patterns is currently being written and will be more detailed than this first edition. The ETA for it's online release is late Q4, 2011. For more detailed coverage of specific patterns, you may be interested in my posts on the Pub/Sub (Observer) or Decorator patterns. At the beginning of this book I will be focusing on a discussion about the importance and history of design patterns in any programming language. Patterns are not an exact solution. V.8 ... et pourquoi pas ? © 2009 - Webdesigner/Intégratrice xHTML-CSS-JS. The Essentials of Writing High Quality JavaScript. Twice a month, we revisit some of our readers’ favorite posts from throughout the history of Nettuts+.

This tutorial was first published in October, 2010. The brilliant Stoyan Stefanov, in promotion of his book, "JavaScript Patterns," was kind enough to contribute an excerpt of the book for our readers, which details the essentials of writing high quality JavaScript, such as avoiding globals, using single var declarations, pre-caching length in loops, following coding conventions, and more.

This excerpt also includes some habits not necessarily related to the code itself, but more about the overall code creation process, including writing API documentation, conducting peer reviews, and running JSLint. These habits and best practices can help you write better, more understandable, and maintainable code—code to be proud of (and be able to figure out) when revisiting it months and years down the road. Software bugs are costly to fix.

Maintainable code means code that: Chapter 4 The amazing em unit and other best practices. JavaScript Garden. Although JavaScript deals fine with the syntax of two matching curly braces for blocks, it does not support block scope; hence, all that is left in the language is function scope. function test() { // a scope for(var i = 0; i < 10; i++) { // not a scope // count } console.log(i); // 10} There are also no distinct namespaces in JavaScript, which means that everything gets defined in one globally shared namespace. Each time a variable is referenced, JavaScript will traverse upwards through all the scopes until it finds it. In the case that it reaches the global scope and still has not found the requested name, it will raise a ReferenceError. The Bane of Global Variables // script Afoo = '42'; // script Bvar foo = '42' The above two scripts do not have the same effect.

Again, that is not at all the same effect: not using var can have major implications. // global scopevar foo = 42;function test() { // local scope foo = 21;}test();foo; // 21 Local Variables var foo = 3; bar = 4;}test(10); Hoisting. JavaScript Guide - MDC Doc Center. The JavaScript Guide shows you how to use JavaScript and gives an overview of the language. If you need exhaustive information about a language feature, have a look at the JavaScript reference. This Guide is divided into the following chapters.

Introduction Grammar and types Control flow and error handling Loops and iteration Functions Expressions and operators Numbers and dates Text formatting Indexed collections Keyed collections Working with objects Details of the object model Promises Iterators and generators. Dive Into Python. PEP 8 -- Style Guide for Python Code.

Code should be written in a way that does not disadvantage other implementations of Python (PyPy, Jython, IronPython, Cython, Psyco, and such).For example, do not rely on CPython's efficient implementation of in-place string concatenation for statements in the form a += b or a = a + b. This optimization is fragile even in CPython (it only works for some types) and isn't present at all in implementations that don't use refcounting. In performance sensitive parts of the library, the ''.join() form should be used instead. This will ensure that concatenation occurs in linear time across various implementations.Comparisons to singletons like None should always be done with is or is not, never the equality operators.Also, beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context!

Table of Contents. Duck typing. When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck.[1] In duck typing, a programmer is only concerned with ensuring that objects behave as demanded of them in a given context, rather than ensuring that they are of a specific type. For example, in a non-duck-typed language, one would create a function that requires that the object passed into it be of type Duck, in order to ensure that that function can then use the object's walk and quack methods.

In a duck-typed language, the function would take an object of any type and simply call its walk and quack methods, producing a run-time error if they are not defined. Instead of specifying types formally, duck typing practices rely on documentation, clear code, and testing to ensure correct use. Concept examples[edit] Consider the following pseudo-code for a duck-typed language: 9 [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6] apples and oranges, apples and oranges, apples and oranges, In C#[edit]