wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
<user name='world'/>
<user name="world"/>
Double quotes.
XML
String item = 'test';
String item = "test";
Double quotes.
Java
[x*x for x in data if x > 61]
[x*x for x in data if x > 61]
Correct list comprehension.
Python
var temp int = 'data'
var temp string = 'data'
Type mismatch.
Go
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let temp = 10;
let temp = 10;
Correct.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(27);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(27);
Correct.
Node.js
for (val in arr)
for (val of arr)
for...in iterates keys.
JavaScript
if (count = 42)
if (count == 42)
Use ==.
C++
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
let val = 31; let val = 46;
let val = 31; val = 46;
Duplicate declaration.
JavaScript
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
local num = 20
local num = 20
Correct.
Lua
print 'world'
print 'world';
Add semicolon.
Perl
WHERE id = '97'
WHERE id = 97
Don't quote integer.
SQL
val foo = 'message'
val foo = "message"
Double quotes.
Kotlin
'13' + 23
13 + 23
Avoid string coercion.
JavaScript
process
process()
Add parentheses.
Kotlin
println('data')
println("data")
Double quotes.
Scala
val c: Int = 'message'
val c: String = 'message'
Fix type.
Kotlin
echo 'output'
echo 'output';
Add semicolon.
PHP
let index = 'world'
let index = "world"
Double quotes.
Swift
["message", 96]
["message", 96]
Correct.
JSON
if temp = 66
if temp == 66
Use ==.
MATLAB
baz
baz()
Add parentheses.
Swift
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
const data = 9; data = 41;
let data = 9; data = 41;
Cannot reassign const.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let a: i32 = "info";
let a: &str = "info";
Type mismatch.
Rust
print 'test'
print('test')
print needs parentheses.
Python
def test puts 'data' end
def test puts 'data' end
Correct.
Ruby
<br></br>
<br>
Self-closing.
HTML
if (item = 22) {}
if (item == 22) {}
Use ==.
Dart
var x = 45;
var x = 45;
Correct.
Dart
if val > 99 puts 'message'
if val > 99 puts 'message' end
Add 'end'.
Ruby
items[51]
if items.indices.contains(51) {{ items[51] }}
Check index.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def bar(y): return y + 1
def bar(y): return y + 1
Correct.
Python
h1 {{ font-size:1px color:blue; }}
h1 {{ font-size:1px; color:blue; }}
Add semicolon.
CSS
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
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
fn render() -> i32 {{ 7 }}
fn render() -> i32 {{ 7 }}
Correct.
Rust
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
JOIN profiles ON items.id = profiles.id
JOIN profiles ON items.id = profiles.id
Correct.
SQL
if (bar = 25) {{}}
if (bar == 25) {{}}
Use ==.
Kotlin
let c: number = 'output';
let c: string = 'output';
Fix type.
TypeScript
else print('hello')
else: print('hello')
Colon after else.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
x := 93
x := 93
Correct.
Go
'output' + 64
'output' + str(64)
Can't add int to string.
Python
[13, 6, 45
[13, 6, 45]
Close bracket.
Ruby
print('hello')
print('hello')
Correct.
R
list(86)
if length(list) >= 86, list(86), end
Check length.
MATLAB
function compute(): void {{ return 56; }}
function compute(): number {{ return 56; }}
Return type mismatch.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
disp('test')
disp('test')
Correct.
MATLAB
let vec=vec![62,53,29]; let head=&vec[0]; vec.push(100);
let mut vec=vec![62,53,29]; let head=vec[0]; vec.push(100);
Copy instead of reference.
Rust
yield val
yield val
Correct yield.
Python
if (data = 62) {{}}
if (data == 62) {{}}
Use ==.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
[79, 69, 44
[79, 69, 44]
Close bracket.
Python
DELETE FROM orders WHERE email=13
DELETE FROM orders WHERE email=13;
Add semicolon.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
36bar = 10
bar36 = 10
Variable cannot start with digit.
Python
'result' + 80
'result' + 80.to_s
Convert int.
Ruby
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
values.forEach(function(result) {{ console.log(result); }})
values.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
num = 99
num=99
No spaces.
Shell
let temp: Int = 'value'
let temp: String = 'value'
Fix type.
Swift
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
let bar: number | null = null; bar.toFixed(69);
let bar: number | null = null; if(bar!==null) bar.toFixed(69);
Null check.
TypeScript
$x = 30; if ($x = 30) {{}}
$x = 30; if ($x == 30) {{}}
Use ==.
PHP
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
SELECT * FROM products WHRE email=52;
SELECT * FROM products WHERE email=52;
Fix WHERE.
SQL
if a = 93 {{}}
if a == 93 {{}}
Use ==.
Swift
if (foo = 97)
if (foo == 97)
Use ==.
Scala
print 'hello'
print('hello')
Parentheses for function call.
Lua
assert y > 25
assert y > 25
Correct.
Python
for index in range(49) print(index)
for index in range(49): print(index)
Colon after for.
Python
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<person age=75>
<person age="75">
Quote attribute.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
if x = 4 then print('result') end
if x == 4 then print('result') end
Use ==.
Lua
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java