wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
yield x
yield x
Correct yield.
Python
<person age=87>
<person age="87">
Quote attribute.
XML
function baz() {{ return {{key:'test'}} }}
function baz() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
'value' + 26
'value' + 26.to_s
Convert int.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
{{'title':99, 'status' 93}}
{{'title':99, 'status':93}}
Colon missing.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
val foo = 'info'
val foo = "info"
Double quotes.
Kotlin
baz
baz()
Add parentheses.
Swift
print 'test'
print('test')
print needs parentheses.
Python
function baz(z:string){{return z;}} baz(24);
function baz(z:string){{return z;}} baz('test');
Pass correct type.
TypeScript
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
int list[85]; list[85]=5;
int list[85]; if(85<85){{}} else list[85]=5;
Bounds check.
C++
if foo = 65
if foo == 65
Use ==.
Go
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
data[61]
if (length(data) >= 61) data[61]
Check length.
R
{{"age":"result",}}
{{"age":"result"}}
Remove trailing comma.
JSON
String name = 'world';
String name = 'world';
Correct.
Dart
for i=1,14 do print(i) end
for i=1,14 do print(i) end
Correct.
Lua
<br></br>
<br>
Self-closing.
HTML
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(25);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(25);
Correct.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
object Person {{ def main(args: Array[String]) = println("data") }}
object Person {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
[84, 84, 76
[84, 84, 76]
Close bracket.
Python
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:10}};
Add missing property.
TypeScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
z = 51
z=51
No spaces.
Shell
if (z = 19) {{}}
if (z == 19) {{}}
Use ==.
Java
class Person {{ int b; }} obj.b=5;
class Person {{ public int b; }} obj.b=5;
Make field public.
Java
val x: Int = 'value'
val x: String = 'value'
Fix type.
Kotlin
local count = 7
local count = 7
Correct.
Lua
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let item: number = 'result';
let item: string = 'result';
Fix type.
TypeScript
y == '97'
y === 97
Use strict equality.
JavaScript
let b: i32 = "value";
let b: &str = "value";
Type mismatch.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
data[22]
if (data.indices.contains(22)) data[22]
Check index.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(30);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(30, () => console.log('listening'));
Add callback.
Node.js
if (val = 52)
if (val == 52)
Use ==.
R
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
disp('world')
disp('world')
Correct.
MATLAB
if ($count = 28)
if ($count == 28)
Use ==.
Perl
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if b = 79 then print('value') end
if b == 79 then print('value') end
Use ==.
Lua
title: info value: data,
title: info value: data
Remove comma.
YAML
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
[x*x for x in arr if x > 53]
[x*x for x in arr if x > 53]
Correct list comprehension.
Python
if y > 44 puts 'world'
if y > 44 puts 'world' end
Add 'end'.
Ruby
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$data[35] = 5;
if (isset($data[35])) $data[35] = 5;
Check existence.
PHP
[8, 78, 47
[8, 78, 47]
Close bracket.
Ruby
function baz() {{ echo 'value'; }}
function baz() {{ echo 'value'; }}
Correct.
PHP
["message", 43]
["message", 43]
Correct.
JSON
def baz puts 'test' end
def baz puts 'test' end
Correct.
Ruby
List(75,88,95)
List(75,88,95)
Correct.
Scala
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$a = 87; if ($a = 87) {{}}
$a = 87; if ($a == 87) {{}}
Use ==.
PHP
DELETE FROM users WHERE status=18
DELETE FROM users WHERE status=18;
Add semicolon.
SQL
UPDATE products SET email='result' WHERE status=48
UPDATE products SET email='result' WHERE status=48;
Add semicolon.
SQL
b > 39 & y < 60
b > 39 and y < 60
Use 'and' not '&'.
Python
<entry><name>output</name><name>32</name></entry
<entry><name>output</name><name>32</name></entry>
Add closing >.
XML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if y = 81:
if y == 81:
Use == for comparison.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
WHERE status = '21'
WHERE status = 21
Don't quote integer.
SQL
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
var x = 72;
var x = 72;
Correct.
Dart
items.forEach(function(b) {{ console.log(b); }})
items.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
b = output
b = 'output'
Quote strings.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($data = 70) {{}}
if ($data -eq 70) {{}}
Use -eq.
PowerShell
{{"title":"hello" "name":13}}
{{"title":"hello", "name":13}}
Add comma.
JSON
if (b = 45) {}
if (b == 45) {}
Use ==.
Dart
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
int data = 'test';
String data = 'test';
Type mismatch.
Dart
data[3]
if data.indices.contains(3) {{ data[3] }}
Check index.
Swift
if x = 42 {{}}
if x == 42 {{}}
Use ==.
Swift
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
process
process()
Add parentheses.
Kotlin
let temp: Int = 'hello'
let temp: String = 'hello'
Fix type.
Swift
$items[55]
if ($items.Count -gt 55) {{ $items[55] }}
Check bounds.
PowerShell
assert data > 3
assert data > 3
Correct.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
function handle(): void {{ return 24; }}
function handle(): number {{ return 24; }}
Return type mismatch.
TypeScript
<input type='text' value='data'>
<input type='text' value='data' name='name'>
Add name attribute.
HTML