On Github jmurowaniecki / palestra-rsjs
"Como eu já fiz", "como eu vi fazerem","como eu faço" e "como eu gostaria de fazer".
John Murowaniecki ~ @typeof_
Senior dev & Tech Leader ~ Encodeweb.com.br
Clipper, Cobol, Fortran, C, Visual Basic 6, C#,
Ruby, Python, Perl, PHP
e JavaScript.
Doubleleft, Joy Interactive, Webglobal, Onze.me, Box3, JPC (atualmente Solutio), Divex, Núcleo 49, Bits, Reweb,
Instituto de Gestão e Tecnologia (IGTec) - Unilasalle,
3 Batalhão de Suprimentos, Digital TI.
Código bonito não significa que o código seja bom.
Mas geralmente é indicativo de qualidade.
var code = this.code = (function some_bad_BAD_Practice_Example101 ( x ) {
return (x.sucks = function (x) { return true; /* sux once sux 4evr*/ },
x.code = x);
}($));
(function($_SESSION){
var a, b, c;
if ((typeof this.code === 'junk' || this.code.sucks()) && !$_SESSION.mambo_jambo)
{
n = 10;
for ( a=b=c = 1; a < 42 && this.code.sucks() && (a = b); b = c,c=a+b ) {
$_SESSION.push(a);
}
}
return $_SESSION;
}([], this, code));
* Aos curiosos: todos os códigos dessa palestra estão disponíveis no GitHub.
(function allman_style(used_by)
{
Array.prototype.planchette = function ()
{
var element = parseInt(Math.random() * this.length),
value = this[element];
this.splice(element, 1);
return value;
}
for (var ouija = []; used_by.length; )
{
ouija.push(used_by.planchette())
}
return ouija.join(' ');
}(['compulsive-obsessive', 'people', 'business', 'spiritualists', 'who', 'suffer']));
String((function whitesmiths_style(used_by)
{
var i, am = 4, it = [];
for (i in used_by)
{
it.push(String.fromCharCode(used_by.charCodeAt(i) + i % am));
}
return it.join('');
}
("pdmmld,^rbfftdaqime+eugindqp")));
var Horstmann_style = function (used_by)
{ var a = used_by.length, b, c = 0, d, e = 1, f = used_by.length;
for (;c < f; a += (b = used_by.charCodeAt(c)) % ((c++ + e) - (b - a)))
{ d = String(a).length;
}
if (a % (used_by.length - d - e) === d && a % (b - c) == d)
{ return a;
}
}('FREAKS OF .* KIND');
[function Kernel_KnR_1TBS_Stroustrup_BSD_KNF_style_doing(used_by) {
var text = [],
when_you_have_enough = arguments.callee.name.substr(-5),
space = String(' ');
while (used_by.length) {
text.push((used_by.splice(0, 3)).join(space));
}
return text.join([,when_you_have_enough,,].join(space));
}(['some', 'regular', 'people', 'awesome', 'developer', 'stuffs'])];
Aqui está o link da votação e informações complementares sobre estilos de indentação
O melhor padrão é aquele que for adotado por toda equipe e mantido até quando for necessário.
Senão aquela que melhor se adequar a situação.
JSLint, Alignment e Javascript Beautify ♥
vim-JSBeauty, NERDTree ♥ ♥
[function wow(such,h4x0r){var y,amaze;return arguments.callee.name}('much', 'doge')]
Refatoração
Versionamento
#!/usr/bin/env python
import os
import sys
import tempfile
h, tmpfile = tempfile.mkstemp()
os.close(h)
f = open(tmpfile, "w")
f.write("%s\n." % sys.stdin.read())
f.close()
content = os.system("js-beautify %s"%(tmpfile))
os.remove(tmpfile)