summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bash.html.markdown13
-rw-r--r--c.html.markdown9
-rw-r--r--cs-cz/python3.html.markdown6
-rw-r--r--d.html.markdown50
-rw-r--r--pt-br/c-pt.html.markdown19
-rw-r--r--xml.html.markdown4
6 files changed, 63 insertions, 38 deletions
diff --git a/bash.html.markdown b/bash.html.markdown
index 191f916a..211d2944 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -90,17 +90,26 @@ else
echo "Your name is your username"
fi
+# NOTE: if $Name is empty, bash sees the above condition as:
+if [ -ne $USER ]
+# which is invalid syntax
+# so the "safe" way to use potentially empty variables in bash is:
+if [ "$Name" -ne $USER ] ...
+# which, when $Name is empty, is seen by bash as:
+if [ "" -ne $USER ] ...
+# which works as expected
+
# There is also conditional execution
echo "Always executed" || echo "Only executed if first command fails"
echo "Always executed" && echo "Only executed if first command does NOT fail"
# To use && and || with if statements, you need multiple pairs of square brackets:
-if [ $Name == "Steve" ] && [ $Age -eq 15 ]
+if [ "$Name" == "Steve" ] && [ "$Age" -eq 15 ]
then
echo "This will run if $Name is Steve AND $Age is 15."
fi
-if [ $Name == "Daniya" ] || [ $Name == "Zach" ]
+if [ "$Name" == "Daniya" ] || [ "$Name" == "Zach" ]
then
echo "This will run if $Name is Daniya OR Zach."
fi
diff --git a/c.html.markdown b/c.html.markdown
index 3339032f..bfdf276c 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -54,6 +54,8 @@ int function_2(void);
// Must declare a 'function prototype' before main() when functions occur after
// your main() function.
int add_two_ints(int x1, int x2); // function prototype
+// although `int add_two_ints(int, int);` is also valid (no need to name the args),
+// it is recommended to name arguments in the prototype as well for easier inspection
// Your program's entry point is a function called
// main with an integer return type.
@@ -74,6 +76,9 @@ int main (int argc, char** argv)
///////////////////////////////////////
// Types
///////////////////////////////////////
+
+ // All variables MUST be declared at the top of the current block scope
+ // we declare them dynamically along the code for the sake of the tutorial
// ints are usually 4 bytes
int x_int = 0;
@@ -232,7 +237,7 @@ int main (int argc, char** argv)
0 || 1; // => 1 (Logical or)
0 || 0; // => 0
- // Conditional expression ( ? : )
+ // Conditional ternary expression ( ? : )
int e = 5;
int f = 10;
int z;
@@ -302,6 +307,8 @@ int main (int argc, char** argv)
for (i = 0; i <= 5; i++) {
; // use semicolon to act as the body (null statement)
}
+ // Or
+ for (i = 0; i <= 5; i++);
// branching with multiple choices: switch()
switch (a) {
diff --git a/cs-cz/python3.html.markdown b/cs-cz/python3.html.markdown
index 11c8a654..6d2fd1eb 100644
--- a/cs-cz/python3.html.markdown
+++ b/cs-cz/python3.html.markdown
@@ -48,7 +48,7 @@ Poznámka: Tento článek je zaměřen na Python 3. Zde se můžete [naučit sta
-5 // 3 # => -2
-5.0 // 3.0 # => -2.0
-# Pokud použiteje desetinné číslo, výsledek je jím také
+# Pokud použijete desetinné číslo, výsledek je jím také
3 * 2.0 # => 6.0
# Modulo
@@ -420,7 +420,7 @@ next(iterator) # Vyhodí StopIteration
## 4. Funkce
####################################################
-# Pro vytvoření nové funkce použijte def
+# Pro vytvoření nové funkce použijte klíčové slovo def
def secist(x, y):
print("x je {} a y je {}".format(x, y))
return x + y # Hodnoty se vrací pomocí return
@@ -520,7 +520,7 @@ class Clovek(object):
# podtržítka na začátku a na konci značí, že se jedná o atribut nebo
# objekt využívaný Pythonem ke speciálním účelům, ale můžete sami
# definovat jeho chování. Metody jako __init__, __str__, __repr__
- # a další se nazývají "magické metody". Nikdy nepoužívejte toto
+ # a další se nazývají "magické metody". Nikdy nepoužívejte toto
# speciální pojmenování pro běžné metody.
def __init__(self, jmeno):
# Přiřazení parametru do atributu instance jmeno
diff --git a/d.html.markdown b/d.html.markdown
index 88a83e41..80c1dc65 100644
--- a/d.html.markdown
+++ b/d.html.markdown
@@ -74,16 +74,18 @@ are passed to functions by value (i.e. copied) and classes are passed by referen
we can use templates to parameterize all of these on both types and values!
```c
-// Here, T is a type parameter. Think <T> from C++/C#/Java
+// Here, 'T' is a type parameter. Think '<T>' from C++/C#/Java.
struct LinkedList(T) {
T data = null;
- LinkedList!(T)* next; // The ! is used to instaniate a parameterized type. Again, think <T>
+
+ // Use '!' to instantiate a parameterized type. Again, think '<T>'.
+ LinkedList!(T)* next;
}
class BinTree(T) {
T data = null;
- // If there is only one template parameter, we can omit the parentheses
+ // If there is only one template parameter, we can omit the parentheses.
BinTree!T left;
BinTree!T right;
}
@@ -98,13 +100,11 @@ enum Day {
Saturday,
}
-// Use alias to create abbreviations for types
-
+// Use alias to create abbreviations for types.
alias IntList = LinkedList!int;
alias NumTree = BinTree!double;
// We can create function templates as well!
-
T max(T)(T a, T b) {
if(a < b)
return b;
@@ -112,9 +112,8 @@ T max(T)(T a, T b) {
return a;
}
-// Use the ref keyword to ensure pass by referece.
-// That is, even if a and b are value types, they
-// will always be passed by reference to swap
+// Use the ref keyword to ensure pass by reference. That is, even if 'a' and 'b'
+// are value types, they will always be passed by reference to 'swap()'.
void swap(T)(ref T a, ref T b) {
auto temp = a;
@@ -122,13 +121,13 @@ void swap(T)(ref T a, ref T b) {
b = temp;
}
-// With templates, we can also parameterize on values, not just types
+// With templates, we can also parameterize on values, not just types.
class Matrix(uint m, uint n, T = int) {
T[m] rows;
T[n] columns;
}
-auto mat = new Matrix!(3, 3); // We've defaulted type T to int
+auto mat = new Matrix!(3, 3); // We've defaulted type 'T' to 'int'.
```
@@ -138,21 +137,20 @@ have the syntax of POD structures (`structure.x = 7`) with the semantics of
getter and setter methods (`object.setX(7)`)!
```c
-// Consider a class parameterized on a types T, U
-
+// Consider a class parameterized on types 'T' & 'U'.
class MyClass(T, U) {
T _data;
U _other;
-
}
-// And "getter" and "setter" methods like so
+// And "getter" and "setter" methods like so:
class MyClass(T, U) {
T _data;
U _other;
- // Constructors are always named `this`
+ // Constructors are always named 'this'.
this(T t, U u) {
+ // This will call the setter methods below.
data = t;
other = u;
}
@@ -175,16 +173,24 @@ class MyClass(T, U) {
_other = u;
}
}
-// And we use them in this manner
+// And we use them in this manner:
void main() {
- auto mc = MyClass!(int, string);
+ auto mc = new MyClass!(int, string)(7, "seven");
+
+ // Import the 'stdio' module from the standard library for writing to
+ // console (imports can be local to a scope).
+ import std.stdio;
+
+ // Call the getters to fetch the values.
+ writefln("Earlier: data = %d, str = %s", mc.data, mc.other);
- mc.data = 7;
- mc.other = "seven";
+ // Call the setters to assign new values.
+ mc.data = 8;
+ mc.other = "eight";
- writeln(mc.data);
- writeln(mc.other);
+ // Call the getters again to fetch the new values.
+ writefln("Later: data = %d, str = %s", mc.data, mc.other);
}
```
diff --git a/pt-br/c-pt.html.markdown b/pt-br/c-pt.html.markdown
index 451df4f3..43688724 100644
--- a/pt-br/c-pt.html.markdown
+++ b/pt-br/c-pt.html.markdown
@@ -6,6 +6,7 @@ contributors:
- ["Árpád Goretity", "http://twitter.com/H2CO3_iOS"]
translators:
- ["João Farias", "https://github.com/JoaoGFarias"]
+ - ["Elton Viana", "https://github.com/eltonvs"]
lang: pt-br
filename: c-pt.el
---
@@ -139,13 +140,13 @@ int main() {
int var_length_array[size]; // declara o VLA
printf("sizeof array = %zu\n", sizeof var_length_array);
- //Uma possível saída para esse programa seria:
- // > Entre o tamanho do array:: 10
+ // Uma possível saída para esse programa seria:
+ // > Entre o tamanho do array: 10
// > sizeof array = 40
// String são apenas arrays de caracteres terminados por um
- // byte NUL (0x00), representado em string pelo caracter especial '\0'.
- // (Não precisamos incluir o byte NUL em literais de string; o compilador
+ // byte nulo (0x00), representado em string pelo caracter especial '\0'.
+ // (Não precisamos incluir o byte nulo em literais de string; o compilador
// o insere ao final do array para nós.)
char uma_string[20] = "Isto é uma string";
// Observe que 'é' não está na tabela ASCII
@@ -153,8 +154,8 @@ int main() {
// Porém, comentários podem conter acentos
printf("%s\n", uma_string); // %s formata a string
- printf("%d\n", uma_string[16]); // => 0
- // i.e., byte #17 é 0 (assim como 18, 19, e 20)
+ printf("%d\n", uma_string[17]); // => 0
+ // i.e., byte #18 é 0 (assim como o 19°, 20°, 21°...)
// Se temos caracteres entre aspas simples, temos um caracter literal.
// Seu tipo é `int`, *não* `char` (por razões históricas).
@@ -220,11 +221,11 @@ int main() {
0 || 1; // => 1 (Ou lógico)
0 || 0; // => 0
- //Expressão condicional ( ? : )
+ //Expressão condicional ternária ( ? : )
int a = 5;
int b = 10;
int z;
- z = (a > b) ? a : b; // => 10 "se a > b retorne a, senão retorne b."
+ z = (a > b) ? a : b; // => 10 "se a > b retorne a, senão retorne b."
//Operadores de incremento e decremento:
char *s = "iLoveC";
@@ -290,6 +291,8 @@ int main() {
for (i = 0; i <= 5; i++) {
; // Use ponto e vírgula para agir como um corpo (declaração nula)
}
+ // Ou
+ for (i = 0; i <= 5; i++);
// Criando branchs com escolhas múltiplas: switch()
switch (alguma_expressao_integral) {
diff --git a/xml.html.markdown b/xml.html.markdown
index 4d33e614..547deb08 100644
--- a/xml.html.markdown
+++ b/xml.html.markdown
@@ -83,7 +83,7 @@ With this tool, you can check the XML data outside the application logic.
<!DOCTYPE note SYSTEM "Bookstore.dtd">
<bookstore>
<book category="COOKING">
- <title >Everyday Italian</title>
+ <title>Everyday Italian</title>
<price>30.00</price>
</book>
</bookstore>
@@ -121,7 +121,7 @@ With this tool, you can check the XML data outside the application logic.
<bookstore>
<book category="COOKING">
- <title >Everyday Italian</title>
+ <title>Everyday Italian</title>
<price>30.00</price>
</book>
</bookstore>