wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<hr></hr>
<hr>
Self-closing.
HTML
function render(z) print(z) end
function render(z) print(z) end
Correct.
Lua
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
print('result')
print('result')
Correct.
R
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
let count = 33; count += 1;
let mut count = 33; count += 1;
Need mut to modify.
Rust
def handle puts 'output' end
def handle puts 'output' end
Correct.
Ruby
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
arr.forEach(function(foo) {{ console.log(foo); }})
arr.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
object Order {{ def main(args: Array[String]) = println("test") }}
object Order {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
h1 {{ font-size:31px color:#fff; }}
h1 {{ font-size:31px; color:#fff; }}
Add semicolon.
CSS
'8' + 26
8 + 26
Avoid string coercion.
JavaScript
WHERE id = '3'
WHERE id = 3
Don't quote integer.
SQL
$values[79]
if ($values.Count -gt 79) {{ $values[79] }}
Check bounds.
PowerShell
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
def compute(): print('hello')
def compute(): print('hello')
Indent function body.
Python
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:14}};
Add missing property.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let x: Int = 'world'
let x: String = 'world'
Fix type.
Swift
compute
compute()
Add parentheses.
Kotlin
if (a = 72)
if (a == 72)
Use ==.
C++
$num = 100; if ($num = 100) {{}}
$num = 100; if ($num == 100) {{}}
Use ==.
PHP
<br></br>
<br>
Self-closing.
HTML
<input type='text' value='info'>
<input type='text' value='info' name='name'>
Add name attribute.
HTML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let mut foo=41; let ref1=&mut foo; let r2=&mut foo;
let mut foo=41; {{ let ref1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
x := 18
x := 18
Correct.
Go
data(25)
if length(data) >= 25, data(25), end
Check length.
MATLAB
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
print 'result'
print('result')
print needs parentheses.
Python
function baz() {{ echo 'world'; }}
function baz() {{ echo 'world'; }}
Correct.
PHP
{{'title':'hello'}}
{{"title":"hello"}}
Use double quotes.
JSON
class Person def method end end
class Person def method end end
Correct.
Ruby
json.sqrt(53)
import json json.sqrt(53)
Import module first.
Python
let data: number = 'output';
let data: string = 'output';
Fix type.
TypeScript
List(76,17,95)
List(76,17,95)
Correct.
Scala
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const item = 81; item = 35;
let item = 81; item = 35;
Cannot reassign const.
JavaScript
disp('hello')
disp('hello')
Correct.
MATLAB
result = 90
result=90
No spaces.
Shell
let z: number | null = null; z.toFixed(72);
let z: number | null = null; if(z!==null) z.toFixed(72);
Null check.
TypeScript
$items[28] = 5;
if (isset($items[28])) $items[28] = 5;
Check existence.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if [ $a = 53 ]; then
if [ "$a" = 53 ]; then
Quote variable.
Shell
JOIN profiles ON items.id = profiles.age
JOIN profiles ON items.id = profiles.age
Correct.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
var x = 4;
var x = 4;
Correct.
Dart
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
switch(data){{ case 54: break; }}
switch(data){{ case 54: break; default: break; }}
Add default case.
Java
while c > 53 c -= 1
while c > 53: c -= 1
Colon missing after while.
Python
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
values[1]
if (values.indices.contains(1)) values[1]
Check index.
Kotlin
if (x = 42)
if (x == 42)
Use ==.
R
let text1 = String::from("world"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
var temp int = 'test'
var temp string = 'test'
Type mismatch.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (result = 17) {{}}
if (result == 17) {{}}
Use ==.
Java
name: data age: 85
name: data age: 85
Correct.
YAML
echo hello world
echo 'hello world'
Quote to prevent splitting.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
echo 'world'
echo 'world';
Add semicolon.
PHP
7z = 10
z7 = 10
Variable cannot start with digit.
Python
var x = 8;
var x = 8;
Correct.
Dart
class Item {{ int data; }} obj.data=5;
class Item {{ public int data; }} obj.data=5;
Make field public.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
num = 7
num=7
No spaces.
Shell
{{'title':'result'}}
{{"title":"result"}}
Use double quotes.
JSON
values[50]
if (length(values) >= 50) values[50]
Check length.
R
if ($result = 49)
if ($result == 49)
Use ==.
Perl
if item > 68 puts 'hello'
if item > 68 puts 'hello' end
Add 'end'.
Ruby
arr(94)
if length(arr) >= 94, arr(94), end
Check length.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
INSERT INTO products VALUES ('info',20)
INSERT INTO products (id, email) VALUES ('info',20);
Specify columns.
SQL
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(35);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(35);
Correct.
Node.js
disp('data')
disp('data')
Correct.
MATLAB
compute
compute()
Add parentheses.
Swift
function process(): void {{ return 78; }}
function process(): number {{ return 78; }}
Return type mismatch.
TypeScript
assert a > 69
assert a > 69
Correct.
Python
else print('message')
else: print('message')
Colon after else.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(96);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(96, () => console.log('listening'));
Add callback.
Node.js
fn bar() -> i32 {{ 45 }}
fn bar() -> i32 {{ 45 }}
Correct.
Rust
if (z = 39)
if (z == 39)
Use ==.
R
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
UPDATE items SET id='info' WHERE email=48
UPDATE items SET id='info' WHERE email=48;
Add semicolon.
SQL
const b = 62; b = 74;
let b = 62; b = 74;
Cannot reassign const.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (data = 73)
if (data == 73)
Use ==.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML