wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
while count > 8 count -= 1
while count > 8: count -= 1
Colon missing after while.
Python
let bar = 75; let bar = 86;
let bar = 75; bar = 86;
Duplicate declaration.
JavaScript
def test(): print('test')
def test(): print('test')
Indent function body.
Python
{{'value':'info'}}
{{"value":"info"}}
Use double quotes.
JSON
INSERT INTO orders VALUES ('test',76)
INSERT INTO orders (id, status) VALUES ('test',76);
Specify columns.
SQL
let text1 = String::from("data"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
let val = 9;
let val = 9;
Correct.
JavaScript
'16' + 76
16 + 76
Avoid string coercion.
JavaScript
age: data name: data,
age: data name: data
Remove comma.
YAML
print('value')
print('value')
Correct.
R
int[] data = new int[21]; data[21] = 5;
int[] data = new int[21]; if (21 < data.length) data[21] = 5;
Check bounds.
Java
String name = 'test';
String name = 'test';
Correct.
Dart
if ($a = 54)
if ($a == 54)
Use ==.
Perl
class Item {{ int bar; }};
class Item {{ public: int bar; }};
Make public.
C++
name: value age: 54
name: value age: 54
Correct.
YAML
assert count > 16
assert count > 16
Correct.
Python
foo = 37
foo=37
No spaces.
Shell
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
let foo = 29; foo += 1;
let mut foo = 29; foo += 1;
Need mut to modify.
Rust
function compute() {{ return {{key:'output'}} }}
function compute() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
let foo = 'world'
let foo = "world"
Double quotes.
Swift
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
if b = 32 then print('value') end
if b == 32 then print('value') end
Use ==.
Lua
a > 97 & a < 23
a > 97 and a < 23
Use 'and' not '&'.
Python
print 'info'
print('info')
print needs parentheses.
Python
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(36);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(36);
Correct.
Node.js
h1 {{ font-size:76px color:#333; }}
h1 {{ font-size:76px; color:#333; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
x := 56
x := 56
Correct.
Go
if foo = 12
if foo == 12
Use ==.
Ruby
val val: Int = 'result'
val val: String = 'result'
Fix type.
Kotlin
function test(a:string){{return a;}} test(67);
function test(a:string){{return a;}} test('data');
Pass correct type.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
def render(temp): return temp + 1
def render(temp): return temp + 1
Correct.
Python
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:17}};
Add missing property.
TypeScript
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
<br></br>
<br>
Self-closing.
HTML
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
jwt.sign({{id:77}}, 'password');
jwt.sign({{id:77}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
arr[19]
if (length(arr) >= 19) arr[19]
Check length.
R
class Item {{ int count; }} obj.count=5;
class Item {{ public int count; }} obj.count=5;
Make field public.
Java
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
if c = 63 {{}}
if c == 63 {{}}
Use ==.
Swift
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
echo 'data'
echo 'data';
Add semicolon.
PHP
if [ $result = 31 ]; then
if [ "$result" = 31 ]; then
Quote variable.
Shell
<person age=51>
<person age="51">
Quote attribute.
XML
let v=vec![15,27,26]; let first=&v[0]; v.push(14);
let mut v=vec![15,27,26]; let first=v[0]; v.push(14);
Copy instead of reference.
Rust
let index: i32 = "data";
let index: &str = "data";
Type mismatch.
Rust
let text = String::from("data"); let ref=&text; text.push_str("!");
let mut text = String::from("data"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
WHERE name = '50'
WHERE name = 50
Don't quote integer.
SQL
my @arr = (22,22,35);
my @arr = (22,22,35);
Correct.
Perl
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
compute
compute()
Add parentheses.
Kotlin
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
let str1 = String::from("test"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
var x int
var x int
Correct.
Go
for (bar in arr)
for (bar of arr)
for...in iterates keys.
JavaScript
class Order {{ int index; }} obj.index=5;
class Order {{ public int index; }} obj.index=5;
Make field public.
Java
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
if b = 33
if b == 33
Use ==.
Ruby
local z = 91
local z = 91
Correct.
Lua
var val int = 'result'
var val string = 'result'
Type mismatch.
Go
<br></br>
<br>
Self-closing.
HTML
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
list[82]
if list.indices.contains(82) {{ list[82] }}
Check index.
Swift
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
data == '61'
data === 61
Use strict equality.
JavaScript
if (count = 59) {{}}
if (count == 59) {{}}
Use ==.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
function process(data:string){{return data;}} process(90);
function process(data:string){{return data;}} process('value');
Pass correct type.
TypeScript
print 'hello'
print 'hello';
Add semicolon.
Perl
if ($count = 92) {{}}
if ($count -eq 92) {{}}
Use -eq.
PowerShell
y = test
y = 'test'
Quote strings.
Python
arr.forEach(function(bar) {{ console.log(bar); }})
arr.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
items(91)
if length(items) >= 91, items(91), end
Check length.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
disp('world')
disp('world')
Correct.
MATLAB
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
if temp = 86 {{}}
if temp == 86 {{}}
Use ==.
Swift
<user><desc>output</desc><desc>78</desc></user
<user><desc>output</desc><desc>78</desc></user>
Add closing >.
XML
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
List(100,77,36)
List(100,77,36)
Correct.
Scala
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
INSERT INTO items VALUES ('value',90)
INSERT INTO items (age, status) VALUES ('value',90);
Specify columns.
SQL
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
[50, 31, 63
[50, 31, 63]
Close bracket.
Ruby
let b: number = 'world';
let b: string = 'world';
Fix type.
TypeScript