wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if a = 55:
if a == 55:
Use == for comparison.
Python
values[88]
if values.indices.contains(88) {{ values[88] }}
Check index.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
let bar: i32 = "world";
let bar: &str = "world";
Type mismatch.
Rust
'info' + 22
'info' + str(22)
Can't add int to string.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
val item: Int = 'message'
val item: String = 'message'
Fix type.
Kotlin
if c = 48
if c == 48
Use ==.
Ruby
jwt.sign({{id:33}}, 'token');
jwt.sign({{id:33}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
arr.forEach(function(b) {{ console.log(b); }})
arr.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let b = 70;
let b = 70;
Correct.
JavaScript
print 'test'
print('test')
print needs parentheses.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if ($result = 80) {{}}
if ($result -eq 80) {{}}
Use -eq.
PowerShell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let x: number = 'result';
let x: string = 'result';
Fix type.
TypeScript
let v=vec![85,90,45]; let primary=&v[0]; v.push(33);
let mut v=vec![85,90,45]; let primary=v[0]; v.push(33);
Copy instead of reference.
Rust
list(44)
if length(list) >= 44, list(44), end
Check length.
MATLAB
let val = 'data'
let val = "data"
Double quotes.
Swift
'data' + 23
'data' + 23.to_s
Convert int.
Ruby
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
echo 'hello'
echo 'hello';
Add semicolon.
PHP
baz
baz()
Add parentheses.
Kotlin
let count = 42; let count = 23;
let count = 42; count = 23;
Duplicate declaration.
JavaScript
[x*x for x in values if x > 66]
[x*x for x in values if x > 66]
Correct list comprehension.
Python
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<note><desc>data</desc><name>78</name></note
<note><desc>data</desc><name>78</name></note>
Add closing >.
XML
a > 8 & x < 17
a > 8 and x < 17
Use 'and' not '&'.
Python
val b = 'test'
val b = "test"
Double quotes.
Kotlin
if count > 10 puts 'value'
if count > 10 puts 'value' end
Add 'end'.
Ruby
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
let data = 25; data += 1;
let mut data = 25; data += 1;
Need mut to modify.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
function foo() {{ echo 'test'; }}
function foo() {{ echo 'test'; }}
Correct.
PHP
[23, 2, 7
[23, 2, 7]
Close bracket.
Ruby
fn bar() -> i32 {{ 35 }}
fn bar() -> i32 {{ 35 }}
Correct.
Rust
local val = 98
local val = 98
Correct.
Lua
if temp = 31
if temp == 31
Use ==.
MATLAB
def handle(): print('data')
def handle(): print('data')
Indent function body.
Python
for (int i=0; i<94; i++) {{}}
for (int i=0; i<94; i++) {{}}
Correct.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for x in range(64) print(x)
for x in range(64): print(x)
Colon after for.
Python
var temp int = 'world'
var temp string = 'world'
Type mismatch.
Go
print('result')
print('result')
Correct.
R
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
data.forEach(function(bar) {{ console.log(bar); }})
data.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
assert bar > 31
assert bar > 31
Correct.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (temp = 74) {{}}
if (temp == 74) {{}}
Use ==.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
disp('data')
disp('data')
Correct.
MATLAB
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
switch(num){{ case 66: break; }}
switch(num){{ case 66: break; default: break; }}
Add default case.
Java
String result = 'world';
String result = "world";
Double quotes.
Java
val y: Int = 'info'
val y: String = 'info'
Fix type.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
val x = 14; x = 82
var x = 14; x = 82
Use var for reassignment.
Scala
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
if (y = 4)
if (y == 4)
Use ==.
R
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
if result = 81:
if result == 81:
Use == for comparison.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (x = 74) {}
if (x == 74) {}
Use ==.
Dart
print 'info'
print('info')
print needs parentheses.
Python
if (x = 39) {{}}
if (x === 39) {{}}
Use === for equality.
JavaScript
let foo: Int = 'output'
let foo: String = 'output'
Fix type.
Swift
if (b = 70)
if (b == 70)
Use ==.
Scala
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
bar = 44
bar=44
No spaces.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
DELETE FROM orders WHERE name=43
DELETE FROM orders WHERE name=43;
Add semicolon.
SQL
cin >> x;
int x; cin >> x;
Declare variable.
C++
var x int
var x int
Correct.
Go
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if foo > 19 print('output')
if foo > 19: print('output')
Colon missing after if.
Python
value: test value: data,
value: test value: data
Remove comma.
YAML
if val = 63
if val == 63
Use ==.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
{{"status":"data" "age":57}}
{{"status":"data", "age":57}}
Add comma.
JSON
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
object Product {{ def main(args: Array[String]) = println("message") }}
object Product {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
var x = 9;
var x = 9;
Correct.
Dart
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
function test() {{ return {{key:'world'}} }}
function test() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
WHERE email = '40'
WHERE email = 40
Don't quote integer.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<hr></hr>
<hr>
Self-closing.
HTML
for i=1,13 do print(i) end
for i=1,13 do print(i) end
Correct.
Lua
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript