Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 30 additions & 95 deletions 1-js/03-code-quality/01-debugging-chrome/article.md

Large diffs are not rendered by default.

17 changes: 1 addition & 16 deletions 1-js/03-code-quality/02-coding-style/1-style-errors/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,12 @@ function pow(x,n) // <- nenhum espaço entre argumentos
return result;
}

<<<<<<< HEAD
let x=prompt("x?",''), n=prompt("n?",'') // <-- tecnicamente possível,
// mas o melhor é torná-la em 2 linhas, também não existem espaços, e falta o ;
// mas o melhor é a tornar em 2 linhas, também não existem espaços, e falta o ;
if (n<0) // <- nenhum espaço dentro (n < 0), e deveria existir uma linha extra sobre a condição
{ // <- chaveta de abertura numa linha em separado
// abaixo - linhas longas podem ser repartidas por múltiplas linhas para melhorar a legíbilidade
alert(`A potência de ${n} não é suportada, por favor insira um número inteiro maior do que zero`);
=======
let x=prompt("x?",''), n=prompt("n?",'') // <-- technically possible,
// but better make it 2 lines, also there's no spaces and missing ;
if (n<=0) // <- no spaces inside (n <= 0), and should be extra line above it
{ // <- figure bracket on a separate line
// below - long lines can be split into multiple lines for improved readability
alert(`Power ${n} is not supported, please enter an integer number greater than zero`);
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3
}
else // <- poderia ser escrito numa única linha, como "} else {"
{
Expand All @@ -48,14 +39,8 @@ function pow(x, n) {
let x = prompt("x?", "");
let n = prompt("n?", "");

<<<<<<< HEAD
if (n < 0) {
alert(`A potência de ${n} não é suportada, por favor insira um número inteiro maior do que zero`);
=======
if (n <= 0) {
alert(`Power ${n} is not supported,
please enter an integer number greater than zero`);
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3
} else {
alert( pow(x, n) );
}
Expand Down
14 changes: 1 addition & 13 deletions 1-js/03-code-quality/02-coding-style/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ let x = prompt("x?", "");
let n = prompt("n?", "");

if (n < 0) {
<<<<<<< HEAD
alert(`A potência de ${n} não é suportada,
por favor insira um número inteiro positivo`);
=======
alert(`Power ${n} is not supported,
please enter a non-negative integer number`);
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3
} else {
alert( pow(x, n) );
}
Expand Down Expand Up @@ -92,14 +87,7 @@ Por exemplo:
```js
// o acento grave (*backtick*) ` permite repartir uma *string* por múltiplas linhas
let str = `
<<<<<<< HEAD
O TC39 da ECMA International, é um grupo de desenvolvedores e implementadores de JavaScript, académicos, e outros, colaborando com a comunidade para manter e
evoluir a definição de JavaScript.
=======
ECMA International's TC39 is a group of JavaScript developers,
implementers, academics, and more, collaborating with the community
to maintain and evolve the definition of JavaScript.
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3
O TC39 da ECMA International, é um grupo de desenvolvedores e implementadores de JavaScript, académicos, e outros, colaborando com a comunidade para manter e evoluir a definição de JavaScript.
`;
```

Expand Down
24 changes: 0 additions & 24 deletions 1-js/03-code-quality/03-comments/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ Descreva a arquitetura
Documente os parâmetros e o uso da função
: Existe uma sintaxe especial, [JSDoc](http://en.wikipedia.org/wiki/JSDoc), para documentar uma função: o seu uso, parâmetros, e valor retornado.

<<<<<<< HEAD
Por exemplo:

```js
Expand All @@ -134,35 +133,17 @@ Por exemplo:
* @param {number} x O número a elevar.
* @param {number} n A potência, deve ser um número natural.
* @return {number} x elevado à n-ésima potência.
=======
For instance:
```js
/**
* Returns x raised to the n-th power.
*
* @param {number} x The number to raise.
* @param {number} n The power, must be a natural number.
* @return {number} x raised to the n-th power.
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3
*/
function pow(x, n) {
...
}
```

<<<<<<< HEAD
Tais comentários, nos permitem compreender o propósito da função e a usar de forma correta, sem olhar para o seu código.

A propósito, muitos editores, como o [WebStorm](https://www.jetbrains.com/webstorm/, podem também os perceber e os usar para fornecer completação automática de palavras (*autocomplete*), e algumas verificações de código (*code-checking*) automáticas.

Também, existem ferramentas como o [JSDoc 3](https://github.com/jsdoc3/jsdoc), que podem gerar documentação HTML a partir de comentários. Pode ler mais informação sobre o JSDoc em <http://usejsdoc.org/>.
=======
Such comments allow us to understand the purpose of the function and use it the right way without looking in its code.

By the way, many editors like [WebStorm](https://www.jetbrains.com/webstorm/) can understand them as well and use them to provide autocomplete and some automatic code-checking.

Also, there are tools like [JSDoc 3](https://github.com/jsdoc3/jsdoc) that can generate HTML-documentation from the comments. You can read more information about JSDoc at <http://usejsdoc.org/>.
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3

Porque é a tarefa solucionada dessa forma?
: O que está escrito é importante. Mas, o que *não* está escrito pode ser ainda mais importante, para se compreender o que se passa. Porque é a tarefa solucionada exatamente dessa forma? O código não dá resposta alguma.
Expand Down Expand Up @@ -193,12 +174,7 @@ Bons comentários, nos permitem manter o código saudável, voltar a ele após u

**Evite comentários:**

<<<<<<< HEAD
- Que digam "como o código funciona" e "o que faz".
- Coloque-os apenas se for impossível tornar o código tão simples e auto-descritivo que não precise deles.
=======
- That tell "how code works" and "what it does".
- Put them in only if it's impossible to make the code so simple and self-descriptive that it doesn't require them.
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3

Comentários também são utilizados por ferramentas de auto-documentação, como o JSDoc3: elas os lêm e geram documentos em HTML (ou documentos num outro formato).
21 changes: 2 additions & 19 deletions 1-js/03-code-quality/05-testing-mocha/article.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<<<<<<< HEAD
# Teste automatizado com mocha
=======
# Automated testing with Mocha
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3

Teste automatizado será utilizado nos exercícios seguintes, e também é amplamente usado em projetos reais.

Expand Down Expand Up @@ -85,11 +81,7 @@ Assim, o desenvolvimento é *iterativo*. Nós escrevemos a *spec*, a implementam

Vejamos este fluxo de desenvolvimento no nosso caso prático.

<<<<<<< HEAD
O primeiro passo já está completo: nós temos uma *spec* inicial para `pow`. Agora, antes de fazer a implementação, vamos utilizar umas poucas bibliotecas (*libraries*) de JavaScript para executar os testes, apenas para ver se eles estão a funcionar (todos irão falhar).
=======
The first step is already complete: we have an initial spec for `pow`. Now, before making the implementation, let's use few JavaScript libraries to run the tests, just to see that they are working (they will all fail).
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3

## A *spec* em ação

Expand Down Expand Up @@ -171,13 +163,8 @@ Aqui, nós podemos selecionar uma das duas formas para organizar o teste:
assert.equal(pow(2, 3), 8);
});

<<<<<<< HEAD
it("3 elevado a 3 é 27", function() {
assert.equal(pow(3, 3), 27);
=======
it("3 raised to power 4 is 81", function() {
it("3 elevado a 4 é 81", function() {
assert.equal(pow(3, 4), 81);
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3
});

});
Expand All @@ -199,11 +186,7 @@ O resultado:

[iframe height=250 src="pow-2" edit border="1"]

<<<<<<< HEAD
Como nós esperávamos, o segundo teste falhou. Seguramente, a nossa função retorna sempre `8`, enquanto o `assert` espera `27`.
=======
As we could expect, the second test failed. Sure, our function always returns `8`, while the `assert` expects `81`.
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3
Como nós esperávamos, o segundo teste falhou. Seguramente, a nossa função retorna sempre `8`, enquanto o `assert` espera `81`.

## Melhorando a implementação

Expand Down
18 changes: 5 additions & 13 deletions 1-js/03-code-quality/05-testing-mocha/beforeafter.view/test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
<<<<<<< HEAD
describe("teste", function() {
// Mocha, geralmente espera pelos testes por 2 segundos antes de os considerar errados

before(() => alert("Testes iniciados – antes de todos os testes"));
after(() => alert("Testes terminados – depois de todos os testes"));
=======
describe("test", function() {

// Mocha usually waits for the tests for 2 seconds before considering them wrong
this.timeout(200000); // Com este código nós aumentamos esse tempo - neste caso, para 200,000

this.timeout(200000); // With this code we increase this - in this case to 200,000 milliseconds
// Isto, por causa da função "alert", porque se você se demorar a pressionar o botão "OK" oos testes não irão passar!

// This is because of the "alert" function, because if you delay pressing the "OK" button the tests will not pass!

before(() => alert("Testing started – before all tests"));
after(() => alert("Testing finished – after all tests"));
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3
before(() => alert("Testes iniciados – antes de todos os testes"));
after(() => alert("Testes terminados – depois de todos os testes"));

beforeEach(() => alert("antes de um teste – entrando para um teste"));
afterEach(() => alert("depois de um teste – saindo de um teste"));
Expand Down
7 changes: 1 addition & 6 deletions 1-js/03-code-quality/05-testing-mocha/pow-2.view/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ describe("pow", function() {
assert.equal(pow(2, 3), 8);
});

<<<<<<< HEAD
it("3 elevado à potência 3 é 27", function() {
assert.equal(pow(3, 3), 27);
=======
it("3 raised to power 4 is 81", function() {
it("3 elevado à potência 4 é 81", function() {
assert.equal(pow(3, 4), 81);
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3
});

});
4 changes: 0 additions & 4 deletions 1-js/03-code-quality/06-polyfills/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ Here Babel comes to the rescue.

Actually, there are two parts in Babel:

<<<<<<< HEAD
1. First, the transpiler program, which rewrites the code. The developer runs it on their own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build system like [webpack](http://webpack.github.io/) or [brunch](http://brunch.io/) provide means to run transpiler automatically on every code change, so that doesn't involve any time loss from our side.
=======
1. First, the transpiler program, which rewrites the code. The developer runs it on their own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build systems like [webpack](http://webpack.github.io/) provide means to run transpiler automatically on every code change, so that it's very easy to integrate into development process.
>>>>>>> e074a5f825a3d10b0c1e5e82561162f75516d7e3

2. Second, the polyfill.

Expand Down
41 changes: 1 addition & 40 deletions 1-js/04-object-basics/01-object/object-user-delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading