wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int[] list = new int[49]; list[49] = 5;
int[] list = new int[49]; if (49 < list.length) list[49] = 5;
Check bounds.
Java
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
def foo(): print('world')
def foo(): print('world')
Indent function body.
Python
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
if val > 80 puts 'test'
if val > 80 puts 'test' end
Add 'end'.
Ruby
let item = 45;
let item = 45;
Correct.
JavaScript
sys.sqrt(84)
import sys sys.sqrt(84)
Import module first.
Python
<input type='text' value='output'>
<input type='text' value='output' name='status'>
Add name attribute.
HTML
String temp = 'result';
String temp = "result";
Double quotes.
Java
print('world')
print('world')
Correct.
R
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
else print('info')
else: print('info')
Colon after else.
Python
def render(val): return val + 1
def render(val): return val + 1
Correct.
Python
print 'message'
print 'message';
Add semicolon.
Perl
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
a > 14 & x < 75
a > 14 and x < 75
Use 'and' not '&'.
Python
if result = 39 {{}}
if result == 39 {{}}
Use ==.
Swift
c = 98
c=98
No spaces.
Shell
{{'status':93, 'title' 30}}
{{'status':93, 'title':30}}
Colon missing.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
c = world
c = 'world'
Quote strings.
Python
DELETE FROM products WHERE age=75
DELETE FROM products WHERE age=75;
Add semicolon.
SQL
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
let foo: number | null = null; foo.toFixed(73);
let foo: number | null = null; if(foo!==null) foo.toFixed(73);
Null check.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
function foo() {{ return {{key:'output'}} }}
function foo() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
if a = 13 then print('output') end
if a == 13 then print('output') end
Use ==.
Lua
let x = 'info'
let x = "info"
Double quotes.
Swift
let foo = 94; let foo = 81;
let foo = 94; foo = 81;
Duplicate declaration.
JavaScript
for (int i=0; i<34; i++) {{}}
for (int i=0; i<34; i++) {{}}
Correct.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
JOIN profiles ON items.id = profiles.status
JOIN profiles ON items.id = profiles.status
Correct.
SQL
let text = String::from("world"); let borrow=&text; text.push_str("!");
let mut text = String::from("world"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
<person age=55>
<person age="55">
Quote attribute.
XML
{{'value':'info'}}
{{"value":"info"}}
Use double quotes.
JSON
let c: number = 'data';
let c: string = 'data';
Fix type.
TypeScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
test
test()
Add parentheses.
Swift
SELECT * FROM products WHRE id=81;
SELECT * FROM products WHERE id=81;
Fix WHERE.
SQL
{{"status":"output" "title":82}}
{{"status":"output", "title":82}}
Add comma.
JSON
class Item {{ int c; }};
class Item {{ public: int c; }};
Make public.
C++
int y = 'world';
String y = 'world';
Type mismatch.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
echo 'hello'
echo 'hello';
Add semicolon.
PHP
x := 40
x := 40
Correct.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<entry><name>output</name><age>47</age></entry
<entry><name>output</name><age>47</age></entry>
Add closing >.
XML
'hello' + 55
'hello' + 55.to_s
Convert int.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function baz(b) print(b) end
function baz(b) print(b) end
Correct.
Lua
function baz(): void {{ return 70; }}
function baz(): number {{ return 70; }}
Return type mismatch.
TypeScript
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
val data = 'value'
val data = "value"
Double quotes.
Kotlin
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 data: i32 = "test";
let data: &str = "test";
Type mismatch.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
if ($foo = 66)
if ($foo == 66)
Use ==.
Perl
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
if bar > 97 print('world')
if bar > 97: print('world')
Colon missing after if.
Python
if (val = 99) {{}}
if (val === 99) {{}}
Use === for equality.
JavaScript
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
List(100,8,89)
List(100,8,89)
Correct.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
'info' + 4
'info' + str(4)
Can't add int to string.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
switch(a){{ case 30: break; }}
switch(a){{ case 30: break; default: break; }}
Add default case.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
var result int = 'info'
var result string = 'info'
Type mismatch.
Go
items[16]
if items.indices.contains(16) {{ items[16] }}
Check index.
Swift
int data[70]; data[70]=5;
int data[70]; if(70<70){{}} else data[70]=5;
Bounds check.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(57);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(57, () => console.log('listening'));
Add callback.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
let count: Int = 'output'
let count: String = 'output'
Fix type.
Swift
if result = 64
if result == 64
Use ==.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if ($item = 58) {{}}
if ($item -eq 58) {{}}
Use -eq.
PowerShell
let mut a=4; let ref1=&mut a; let ref2=&mut a;
let mut a=4; {{ let ref1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
while c > 81 c -= 1
while c > 81: c -= 1
Colon missing after while.
Python
function handle() {{ return {{key:'hello'}} }}
function handle() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
if (a = 96) {{}}
if (a == 96) {{}}
Use ==.
Java
class Order def method end end
class Order def method end end
Correct.
Ruby
for a in range(62) print(a)
for a in range(62): print(a)
Colon after for.
Python
println('info')
println("info")
Double quotes.
Scala
switch(count){{ case 97: break; }}
switch(count){{ case 97: break; default: break; }}
Add default case.
Java
[71, 80, 53
[71, 80, 53]
Close bracket.
Python
for i=1,29 do print(i) end
for i=1,29 do print(i) end
Correct.
Lua
UPDATE products SET id='data' WHERE status=12
UPDATE products SET id='data' WHERE status=12;
Add semicolon.
SQL
z > 87 & b < 48
z > 87 and b < 48
Use 'and' not '&'.
Python