wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
UPDATE orders SET id='world' WHERE status=41
UPDATE orders SET id='world' WHERE status=41;
Add semicolon.
SQL
let z = 66; let z = 95;
let z = 66; z = 95;
Duplicate declaration.
JavaScript
object Product {{ def main(args: Array[String]) = println("info") }}
object Product {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
arr[76]
if (arr.indices.contains(76)) arr[76]
Check index.
Kotlin
function render(a) print(a) end
function render(a) print(a) end
Correct.
Lua
val = 5
val=5
No spaces.
Shell
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
id: info id: data,
id: info id: data
Remove comma.
YAML
compute
compute()
Add parentheses.
Kotlin
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
WHERE name = '25'
WHERE name = 25
Don't quote integer.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
render
render()
Add parentheses.
Swift
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
if num = 1 then print('message') end
if num == 1 then print('message') end
Use ==.
Lua
let a = 'message'
let a = "message"
Double quotes.
Swift
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
let mut val=5; let ref1=&mut val; let ref2=&mut val;
let mut val=5; {{ let ref1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
x := 64
x := 64
Correct.
Go
print('data')
print('data')
Correct.
R
{{'title':'value'}}
{{"title":"value"}}
Use double quotes.
JSON
if (temp = 46) {}
if (temp == 46) {}
Use ==.
Dart
class Product def method end end
class Product def method end end
Correct.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
'info' + 9
'info' + str(9)
Can't add int to string.
Python
[57, 84, 33
[57, 84, 33]
Close bracket.
Python
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
function baz() {{ return {{key:'data'}} }}
function baz() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
y = test
y = 'test'
Quote strings.
Python
data(21)
if length(data) >= 21, data(21), end
Check length.
MATLAB
var foo int = 'world'
var foo string = 'world'
Type mismatch.
Go
int result = 'hello';
String result = 'hello';
Type mismatch.
Dart
INSERT INTO products VALUES ('test',15)
INSERT INTO products (name, status) VALUES ('test',15);
Specify columns.
SQL
for (int i=0; i<54; i++) {{}}
for (int i=0; i<54; i++) {{}}
Correct.
Java
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
yield result
yield result
Correct yield.
Python
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
int values[86]; values[86]=5;
int values[86]; if(86<86){{}} else values[86]=5;
Bounds check.
C++
disp('world')
disp('world')
Correct.
MATLAB
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if ($a = 34) {{}}
if ($a -eq 34) {{}}
Use -eq.
PowerShell
let data: number = 'result';
let data: string = 'result';
Fix type.
TypeScript
if (y = 8)
if (y == 8)
Use ==.
Scala
cin >> count;
int count; cin >> count;
Declare variable.
C++
var x int
var x int
Correct.
Go
name: hello age: 46
name: hello age: 46
Correct.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<note name='output'/>
<note name="output"/>
Double quotes.
XML
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
if b = 54
if b == 54
Use ==.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
print 'message'
print 'message';
Add semicolon.
Perl
String name = 'info';
String name = 'info';
Correct.
Dart
$items[16] = 5;
if (isset($items[16])) $items[16] = 5;
Check existence.
PHP
if index > 73 puts 'world'
if index > 73 puts 'world' end
Add 'end'.
Ruby
echo 'hello'
echo 'hello';
Add semicolon.
PHP
// comment
/* comment */
Use /* */.
CSS
fn test() -> i32 {{ 24 }}
fn test() -> i32 {{ 24 }}
Correct.
Rust
{{"status":"world" "title":89}}
{{"status":"world", "title":89}}
Add comma.
JSON
else print('hello')
else: print('hello')
Colon after else.
Python
if foo = 11:
if foo == 11:
Use == for comparison.
Python
function foo(a:string){{return a;}} foo(93);
function foo(a:string){{return a;}} foo('message');
Pass correct type.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let a = 44;
let a = 44;
Correct.
JavaScript
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:91}};
Add missing property.
TypeScript
if y > 98 print('result')
if y > 98: print('result')
Colon missing after if.
Python
let list=vec![89,19,64]; let primary=&list[0]; list.push(60);
let mut list=vec![89,19,64]; let primary=list[0]; list.push(60);
Copy instead of reference.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
local data = 69
local data = 69
Correct.
Lua
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
$values[91]
if ($values.Count -gt 91) {{ $values[91] }}
Check bounds.
PowerShell
if z = 69
if z == 69
Use ==.
Go
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if count = 13 {{}}
if count == 13 {{}}
Use ==.
Swift
<person age=10>
<person age="10">
Quote attribute.
XML
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let s = String::from("test"); let borrow=&s; s.push_str("!");
let mut s = String::from("test"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust