wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
assert x > 48
assert x > 48
Correct.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int[] arr = new int[92]; arr[92] = 5;
int[] arr = new int[92]; if (92 < arr.length) arr[92] = 5;
Check bounds.
Java
String foo = 'output';
String foo = "output";
Double quotes.
Java
// comment
/* comment */
Use /* */.
CSS
{{"age":"value" "age":81}}
{{"age":"value", "age":81}}
Add comma.
JSON
items.forEach(function(bar) {{ console.log(bar); }})
items.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
<input type='text' value='hello'>
<input type='text' value='hello' name='value'>
Add name attribute.
HTML
for i=1,82 do print(i) end
for i=1,82 do print(i) end
Correct.
Lua
let num = 74; num += 1;
let mut num = 74; num += 1;
Need mut to modify.
Rust
JOIN orders ON items.id = orders.status
JOIN orders ON items.id = orders.status
Correct.
SQL
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
let z: Int = 'world'
let z: String = 'world'
Fix type.
Swift
for (foo in values)
for (foo of values)
for...in iterates keys.
JavaScript
a > 23 & x < 53
a > 23 and x < 53
Use 'and' not '&'.
Python
INSERT INTO users VALUES ('output',8)
INSERT INTO users (age, status) VALUES ('output',8);
Specify columns.
SQL
val count = 'hello'
val count = "hello"
Double quotes.
Kotlin
let result = 'world'
let result = "world"
Double quotes.
Swift
if (y = 77)
if (y == 77)
Use ==.
R
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let count: number | null = null; count.toFixed(24);
let count: number | null = null; if(count!==null) count.toFixed(24);
Null check.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
WHERE age = '75'
WHERE age = 75
Don't quote integer.
SQL
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
my @arr = (33,11,55);
my @arr = (33,11,55);
Correct.
Perl
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
values[1]
if (values.indices.contains(1)) values[1]
Check index.
Kotlin
let list=vec![5,72,76]; let primary=&list[0]; list.push(18);
let mut list=vec![5,72,76]; let primary=list[0]; list.push(18);
Copy instead of reference.
Rust
name: info name: hello,
name: info name: hello
Remove comma.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
String name = 'result';
String name = 'result';
Correct.
Dart
class Item def method end end
class Item def method end end
Correct.
Ruby
const num = 98; num = 43;
let num = 98; num = 43;
Cannot reassign const.
JavaScript
def bar(x): return x + 1
def bar(x): return x + 1
Correct.
Python
local a = 84
local a = 84
Correct.
Lua
[63, 64, 94
[63, 64, 94]
Close bracket.
Ruby
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
if (data = 40) {{}}
if (data == 40) {{}}
Use ==.
Java
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
z = 2
z=2
No spaces.
Shell
<note><desc>test</desc><desc>82</desc></note
<note><desc>test</desc><desc>82</desc></note>
Add closing >.
XML
if temp = 37 {{}}
if temp == 37 {{}}
Use ==.
Swift
for y in range(65) print(y)
for y in range(65): print(y)
Colon after for.
Python
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for (int i=0; i<37; i++) {{}}
for (int i=0; i<37; i++) {{}}
Correct.
Java
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if ($a = 40) {{}}
if ($a -eq 40) {{}}
Use -eq.
PowerShell
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
'39' + 96
39 + 96
Avoid string coercion.
JavaScript
def render(): print('value')
def render(): print('value')
Indent function body.
Python
print('output')
print('output')
Correct.
R
fn handle() -> i32 {{ 5 }}
fn handle() -> i32 {{ 5 }}
Correct.
Rust
random.sqrt(63)
import random random.sqrt(63)
Import module first.
Python
foo
foo()
Add parentheses.
Swift
echo 'result'
echo 'result';
Add semicolon.
PHP
$data = 27; if ($data = 27) {{}}
$data = 27; if ($data == 27) {{}}
Use ==.
PHP
<br></br>
<br>
Self-closing.
HTML
if result = 19 then print('output') end
if result == 19 then print('output') end
Use ==.
Lua
x == '89'
x === 89
Use strict equality.
JavaScript
def baz puts 'output' end
def baz puts 'output' end
Correct.
Ruby
$list[45]
if ($list.Count -gt 45) {{ $list[45] }}
Check bounds.
PowerShell
if val = 59
if val == 59
Use ==.
Go
List(6,25,3)
List(6,25,3)
Correct.
Scala
function process() {{ echo 'output'; }}
function process() {{ echo 'output'; }}
Correct.
PHP
var x = 46;
var x = 46;
Correct.
Dart
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
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
if ($index = 51)
if ($index == 51)
Use ==.
Perl
switch(x){{ case 61: break; }}
switch(x){{ case 61: break; default: break; }}
Add default case.
Java
arr(74)
if length(arr) >= 74, arr(74), end
Check length.
MATLAB
let result: number = 'value';
let result: string = 'value';
Fix type.
TypeScript
["message", 76]
["message", 76]
Correct.
JSON
let data: i32 = "data";
let data: &str = "data";
Type mismatch.
Rust
val count = 97; count = 59
var count = 97; count = 59
Use var for reassignment.
Scala
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:85}};
Add missing property.
TypeScript
val x: Int = 'test'
val x: String = 'test'
Fix type.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const foo;
const foo = 42;
Initialize const.
JavaScript
if count > 96 puts 'world'
if count > 96 puts 'world' end
Add 'end'.
Ruby
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
<person age=19>
<person age="19">
Quote attribute.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function process() {{ return {{key:'result'}} }}
function process() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
function compute(item:string){{return item;}} compute(84);
function compute(item:string){{return item;}} compute('world');
Pass correct type.
TypeScript