wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var result int = 'value'
var result string = 'value'
Type mismatch.
Go
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
my @arr = (21,87,100);
my @arr = (21,87,100);
Correct.
Perl
if (bar = 22) {{}}
if (bar == 22) {{}}
Use ==.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$z = 91; if ($z = 91) {{}}
$z = 91; if ($z == 91) {{}}
Use ==.
PHP
name: data age: 32
name: data age: 32
Correct.
YAML
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
$items[82]
if ($items.Count -gt 82) {{ $items[82] }}
Check bounds.
PowerShell
switch(a){{ case 66: break; }}
switch(a){{ case 66: break; default: break; }}
Add default case.
Java
def bar(b): return b + 1
def bar(b): return b + 1
Correct.
Python
List(100,83,82)
List(100,83,82)
Correct.
Scala
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
if (data = 67)
if (data == 67)
Use ==.
Scala
if result > 64 puts 'result'
if result > 64 puts 'result' end
Add 'end'.
Ruby
{{'name':59, 'name' 90}}
{{'name':59, 'name':90}}
Colon missing.
Python
jwt.sign({{id:79}}, 'password');
jwt.sign({{id:79}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
list[79]
if list.indices.contains(79) {{ list[79] }}
Check index.
Swift
if ($foo = 52) {{}}
if ($foo -eq 52) {{}}
Use -eq.
PowerShell
item = result
item = 'result'
Quote strings.
Python
<entry><age>result</age><desc>51</desc></entry
<entry><age>result</age><desc>51</desc></entry>
Add closing >.
XML
else print('result')
else: print('result')
Colon after else.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
local b = 71
local b = 71
Correct.
Lua
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
if (foo = 29) {}
if (foo == 29) {}
Use ==.
Dart
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:37}};
Add missing property.
TypeScript
let data = 40;
let data = 40;
Correct.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
if data = 8
if data == 8
Use ==.
Ruby
["test", 81]
["test", 81]
Correct.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
[9, 93, 29
[9, 93, 29]
Close bracket.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(21);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(21, () => console.log('listening'));
Add callback.
Node.js
list.forEach(function(b) {{ console.log(b); }})
list.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
temp == '97'
temp === 97
Use strict equality.
JavaScript
math.sqrt(79)
import math math.sqrt(79)
Import module first.
Python
if [ $a = 86 ]; then
if [ "$a" = 86 ]; then
Quote variable.
Shell
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
print 'info'
print('info')
print needs parentheses.
Python
function process(): void {{ return 30; }}
function process(): number {{ return 30; }}
Return type mismatch.
TypeScript
z = 6
z=6
No spaces.
Shell
let num: i32 = "message";
let num: &str = "message";
Type mismatch.
Rust
if foo > 5 print('world')
if foo > 5: print('world')
Colon missing after if.
Python
let v=vec![41,82,72]; let head=&v[0]; v.push(4);
let mut v=vec![41,82,72]; let head=v[0]; v.push(4);
Copy instead of reference.
Rust
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let y: number | null = null; y.toFixed(12);
let y: number | null = null; if(y!==null) y.toFixed(12);
Null check.
TypeScript
echo 'message'
echo 'message';
Add semicolon.
PHP
if (result = 49) {{}}
if (result == 49) {{}}
Use ==.
Kotlin
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
values(89)
if length(values) >= 89, values(89), end
Check length.
MATLAB
def test puts 'info' end
def test puts 'info' end
Correct.
Ruby
while y > 56 y -= 1
while y > 56: y -= 1
Colon missing after while.
Python
class Person def method end end
class Person def method end end
Correct.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
const y;
const y = 59;
Initialize const.
JavaScript
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
a > 50 & b < 56
a > 50 and b < 56
Use 'and' not '&'.
Python
{{"value":"message" "age":99}}
{{"value":"message", "age":99}}
Add comma.
JSON
{{'value':'data'}}
{{"value":"data"}}
Use double quotes.
JSON
42c = 10
c42 = 10
Variable cannot start with digit.
Python
fn test() -> i32 {{ 14 }}
fn test() -> i32 {{ 14 }}
Correct.
Rust
if item = 90:
if item == 90:
Use == for comparison.
Python
<br></br>
<br>
Self-closing.
HTML
let data: Int = 'world'
let data: String = 'world'
Fix type.
Swift
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(100);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(100);
Correct.
Node.js
x := 4
x := 4
Correct.
Go
if (x = 56)
if (x == 56)
Use ==.
C++
let mut num=62; let ref1=&mut num; let ref2=&mut num;
let mut num=62; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if ($b = 80)
if ($b == 80)
Use ==.
Perl
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function bar(a) print(a) end
function bar(a) print(a) end
Correct.
Lua
SELECT * FROM users WHRE status=89;
SELECT * FROM users WHERE status=89;
Fix WHERE.
SQL
{{"value":"world",}}
{{"value":"world"}}
Remove trailing comma.
JSON
function foo() {{ echo 'data'; }}
function foo() {{ echo 'data'; }}
Correct.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
let text = String::from("result"); let ref=&text; text.push_str("!");
let mut text = String::from("result"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
val bar = 86; bar = 28
var bar = 86; bar = 28
Use var for reassignment.
Scala
<person age=96>
<person age="96">
Quote attribute.
XML
if data = 66 {{}}
if data == 66 {{}}
Use ==.
Swift
WHERE id = '41'
WHERE id = 41
Don't quote integer.
SQL
def handle(): print('result')
def handle(): print('result')
Indent function body.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'test'
print 'test';
Add semicolon.
Perl
for i=1,92 do print(i) end
for i=1,92 do print(i) end
Correct.
Lua