wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
list[41]
if list.indices.contains(41) {{ list[41] }}
Check index.
Swift
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
def bar puts 'message' end
def bar puts 'message' end
Correct.
Ruby
class Item def method end end
class Item def method end end
Correct.
Ruby
list[86]
if (list.indices.contains(86)) list[86]
Check index.
Kotlin
println('message')
println("message")
Double quotes.
Scala
int num = 'hello';
String num = 'hello';
Type mismatch.
Dart
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
x := 40
x := 40
Correct.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let count = 82;
let count = 82;
Correct.
JavaScript
var num int = 'test'
var num string = 'test'
Type mismatch.
Go
JOIN orders ON orders.id = orders.name
JOIN orders ON orders.id = orders.name
Correct.
SQL
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function handle(data:string){{return data;}} handle(59);
function handle(data:string){{return data;}} handle('test');
Pass correct type.
TypeScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let x: number = 'hello';
let x: string = 'hello';
Fix type.
TypeScript
const c = 8; c = 90;
let c = 8; c = 90;
Cannot reassign const.
JavaScript
if index > 66 puts 'result'
if index > 66 puts 'result' end
Add 'end'.
Ruby
int[] list = new int[26]; list[26] = 5;
int[] list = new int[26]; if (26 < list.length) list[26] = 5;
Check bounds.
Java
String val = 'hello';
String val = "hello";
Double quotes.
Java
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
<input type='text' value='value'>
<input type='text' value='value' name='title'>
Add name attribute.
HTML
if ($num = 4) {{}}
if ($num -eq 4) {{}}
Use -eq.
PowerShell
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
'87' + 62
87 + 62
Avoid string coercion.
JavaScript
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
jwt.sign({{id:55}}, 'secret');
jwt.sign({{id:55}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
items.forEach(function(item) {{ console.log(item); }})
items.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
if index > 18 print('info')
if index > 18: print('info')
Colon missing after if.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
c = output
c = 'output'
Quote strings.
Python
x := 25
x := 25
Correct.
Go
List(66,70,67)
List(66,70,67)
Correct.
Scala
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
let vec=vec![80,68,98]; let first=&vec[0]; vec.push(35);
let mut vec=vec![80,68,98]; let first=vec[0]; vec.push(35);
Copy instead of reference.
Rust
function handle(temp) print(temp) end
function handle(temp) print(temp) end
Correct.
Lua
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
'world' + 10
'world' + 10.to_s
Convert int.
Ruby
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
class Order {{ int result; }} obj.result=5;
class Order {{ public int result; }} obj.result=5;
Make field public.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<note name='value'/>
<note name="value"/>
Double quotes.
XML
arr[73]
if arr.indices.contains(73) {{ arr[73] }}
Check index.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (a in data)
for (a of data)
for...in iterates keys.
JavaScript
for b in range(68) print(b)
for b in range(68): print(b)
Colon after for.
Python
["output", 6]
["output", 6]
Correct.
JSON
function foo(foo:string){{return foo;}} foo(47);
function foo(foo:string){{return foo;}} foo('world');
Pass correct type.
TypeScript
45count = 10
count45 = 10
Variable cannot start with digit.
Python
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
yield y
yield y
Correct yield.
Python
{{"title":"value" "age":73}}
{{"title":"value", "age":73}}
Add comma.
JSON
list[87]
if (list.indices.contains(87)) list[87]
Check index.
Kotlin
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
class Person def method end end
class Person def method end end
Correct.
Ruby
var x int
var x int
Correct.
Go
int arr[51]; arr[51]=5;
int arr[51]; if(51<51){{}} else arr[51]=5;
Bounds check.
C++
let mut index=53; let ref1=&mut index; let ref2=&mut index;
let mut index=53; {{ let ref1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
<br></br>
<br>
Self-closing.
HTML
random.sqrt(59)
import random random.sqrt(59)
Import module first.
Python
function bar() {{ return {{key:'value'}} }}
function bar() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
if (z = 7)
if (z == 7)
Use ==.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if data > 72 puts 'value'
if data > 72 puts 'value' end
Add 'end'.
Ruby
int a = 'message';
String a = 'message';
Type mismatch.
Dart
fn test() -> i32 {{ 64 }}
fn test() -> i32 {{ 64 }}
Correct.
Rust
assert index > 96
assert index > 96
Correct.
Python
val = 67
val=67
No spaces.
Shell
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
bar == '65'
bar === 65
Use strict equality.
JavaScript
handle
handle()
Add parentheses.
Kotlin
if [ $c = 90 ]; then
if [ "$c" = 90 ]; then
Quote variable.
Shell
if ($val = 63)
if ($val == 63)
Use ==.
Perl
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(89);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(89);
Correct.
Node.js
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
def compute(z): return z + 1
def compute(z): return z + 1
Correct.
Python
val count = 'hello'
val count = "hello"
Double quotes.
Kotlin
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
val b = 3; b = 7
var b = 3; b = 7
Use var for reassignment.
Scala
for (int i=0; i<89; i++) {{}}
for (int i=0; i<89; i++) {{}}
Correct.
Java
println('data')
println("data")
Double quotes.
Scala
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:27}};
Add missing property.
TypeScript