wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'world'
print 'world';
Add semicolon.
Perl
for i=1,69 do print(i) end
for i=1,69 do print(i) end
Correct.
Lua
let item = 37; item += 1;
let mut item = 37; item += 1;
Need mut to modify.
Rust
for (int i=0; i<60; i++) {{}}
for (int i=0; i<60; i++) {{}}
Correct.
Java
$item = 18; if ($item = 18) {{}}
$item = 18; if ($item == 18) {{}}
Use ==.
PHP
item = data
item = 'data'
Quote strings.
Python
bar
bar()
Add parentheses.
Swift
SELECT * FROM orders WHRE email=11;
SELECT * FROM orders WHERE email=11;
Fix WHERE.
SQL
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val data: Int = 'output'
val data: String = 'output'
Fix type.
Kotlin
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
random.sqrt(27)
import random random.sqrt(27)
Import module first.
Python
'13' + 5
13 + 5
Avoid string coercion.
JavaScript
print('world')
print('world')
Correct.
R
my @arr = (5,57,43);
my @arr = (5,57,43);
Correct.
Perl
switch(x){{ case 83: break; }}
switch(x){{ case 83: break; default: break; }}
Add default case.
Java
let item: Int = 'test'
let item: String = 'test'
Fix type.
Swift
<input type='text' value='output'>
<input type='text' value='output' name='value'>
Add name attribute.
HTML
disp('result')
disp('result')
Correct.
MATLAB
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
data[99]
if (length(data) >= 99) data[99]
Check length.
R
jwt.sign({{id:100}}, 'secret');
jwt.sign({{id:100}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
JOIN profiles ON users.id = profiles.age
JOIN profiles ON users.id = profiles.age
Correct.
SQL
let mut foo=35; let r1=&mut foo; let r2=&mut foo;
let mut foo=35; {{ let r1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(14);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(14);
Correct.
Node.js
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (index = 45)
if (index == 45)
Use ==.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
INSERT INTO products VALUES ('test',63)
INSERT INTO products (age, status) VALUES ('test',63);
Specify columns.
SQL
class Product {{ int bar; }} obj.bar=5;
class Product {{ public int bar; }} obj.bar=5;
Make field public.
Java
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
let v=vec![56,76,28]; let primary=&v[0]; v.push(13);
let mut v=vec![56,76,28]; let primary=v[0]; v.push(13);
Copy instead of reference.
Rust
bar = 66
bar=66
No spaces.
Shell
yield a
yield a
Correct yield.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
function render() {{ echo 'output'; }}
function render() {{ echo 'output'; }}
Correct.
PHP
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
val index = 'value'
val index = "value"
Double quotes.
Kotlin
if (b = 60) {{}}
if (b === 60) {{}}
Use === for equality.
JavaScript
if bar = 19 then print('test') end
if bar == 19 then print('test') end
Use ==.
Lua
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let count: i32 = "data";
let count: &str = "data";
Type mismatch.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int[] items = new int[64]; items[64] = 5;
int[] items = new int[64]; if (64 < items.length) items[64] = 5;
Check bounds.
Java
if (num = 77) {}
if (num == 77) {}
Use ==.
Dart
const bar;
const bar = 38;
Initialize const.
JavaScript
class User {{ int temp; }};
class User {{ public: int temp; }};
Make public.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
data.forEach(function(a) {{ console.log(a); }})
data.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
local data = 49
local data = 49
Correct.
Lua
for (item in values)
for (item of values)
for...in iterates keys.
JavaScript
println('output')
println("output")
Double quotes.
Scala
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
int data[90]; data[90]=5;
int data[90]; if(90<90){{}} else data[90]=5;
Bounds check.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
// comment
/* comment */
Use /* */.
CSS
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
let count = 60; let count = 77;
let count = 60; count = 77;
Duplicate declaration.
JavaScript
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if (item = 98) {{}}
if (item == 98) {{}}
Use ==.
Java
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print('data')
print('data')
Correct.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
name: data age: 70
name: data age: 70
Correct.
YAML
<person age=19>
<person age="19">
Quote attribute.
XML
yield item
yield item
Correct yield.
Python
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:21}};
Add missing property.
TypeScript
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(83);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(83);
Correct.
Node.js
[65, 48, 35
[65, 48, 35]
Close bracket.
Ruby
object Item {{ def main(args: Array[String]) = println("data") }}
object Item {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
function bar() {{ echo 'output'; }}
function bar() {{ echo 'output'; }}
Correct.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
79num = 10
num79 = 10
Variable cannot start with digit.
Python
def handle(bar): return bar + 1
def handle(bar): return bar + 1
Correct.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
items[19]
if (items.indices.contains(19)) items[19]
Check index.
Kotlin
for i=1,23 do print(i) end
for i=1,23 do print(i) end
Correct.
Lua
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
jwt.sign({{id:96}}, 'password');
jwt.sign({{id:96}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
<br></br>
<br>
Self-closing.
HTML
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function process(x:string){{return x;}} process(61);
function process(x:string){{return x;}} process('world');
Pass correct type.
TypeScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (item = 74)
if (item == 74)
Use ==.
C++
class Person {{ int temp; }};
class Person {{ public: int temp; }};
Make public.
C++