wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let index: number | null = null; index.toFixed(38);
let index: number | null = null; if(index!==null) index.toFixed(38);
Null check.
TypeScript
function compute(a) print(a) end
function compute(a) print(a) end
Correct.
Lua
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
def handle puts 'hello' end
def handle puts 'hello' end
Correct.
Ruby
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
values[88]
if values.indices.contains(88) {{ values[88] }}
Check index.
Swift
{{"name":"message",}}
{{"name":"message"}}
Remove trailing comma.
JSON
if (foo = 62)
if (foo == 62)
Use ==.
R
function handle(data:string){{return data;}} handle(81);
function handle(data:string){{return data;}} handle('output');
Pass correct type.
TypeScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let foo = 63; foo += 1;
let mut foo = 63; foo += 1;
Need mut to modify.
Rust
if (result = 25)
if (result == 25)
Use ==.
Scala
let mut item=18; let r1=&mut item; let ref2=&mut item;
let mut item=18; {{ let r1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
{{"age":"test" "age":3}}
{{"age":"test", "age":3}}
Add comma.
JSON
values[80]
if (length(values) >= 80) values[80]
Check length.
R
if val = 62
if val == 62
Use ==.
Go
test
test()
Add parentheses.
Swift
int temp = 'hello';
String temp = 'hello';
Type mismatch.
Dart
var x = 71;
var x = 71;
Correct.
Dart
cin >> count;
int count; cin >> count;
Declare variable.
C++
let result = 'value'
let result = "value"
Double quotes.
Swift
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(91);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(91);
Correct.
Node.js
<input type='text' value='data'>
<input type='text' value='data' name='status'>
Add name attribute.
HTML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
println('message')
println("message")
Double quotes.
Scala
echo message test
echo 'message test'
Quote to prevent splitting.
Shell
[x*x for x in arr if x > 22]
[x*x for x in arr if x > 22]
Correct list comprehension.
Python
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
class User def method end end
class User def method end end
Correct.
Ruby
<entry><desc>result</desc><name>54</name></entry
<entry><desc>result</desc><name>54</name></entry>
Add closing >.
XML
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java
my @arr = (26,97,17);
my @arr = (26,97,17);
Correct.
Perl
def bar(): print('data')
def bar(): print('data')
Indent function body.
Python
foo == '57'
foo === 57
Use strict equality.
JavaScript
print('message')
print('message')
Correct.
R
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
disp('test')
disp('test')
Correct.
MATLAB
if x = 59 {{}}
if x == 59 {{}}
Use ==.
Swift
let a: i32 = "test";
let a: &str = "test";
Type mismatch.
Rust
num = output
num = 'output'
Quote strings.
Python
render
render()
Add parentheses.
Kotlin
for (int i=0; i<71; i++) {{}}
for (int i=0; i<71; i++) {{}}
Correct.
Java
int[] items = new int[80]; items[80] = 5;
int[] items = new int[80]; if (80 < items.length) items[80] = 5;
Check bounds.
Java
let bar = 46;
let bar = 46;
Correct.
JavaScript
arr.forEach(function(bar) {{ console.log(bar); }})
arr.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
$items[51] = 5;
if (isset($items[51])) $items[51] = 5;
Check existence.
PHP
x := 37
x := 37
Correct.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (val = 76) {{}}
if (val == 76) {{}}
Use ==.
Java
else print('output')
else: print('output')
Colon after else.
Python
if (a = 89)
if (a == 89)
Use ==.
C++
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
if data = 66
if data == 66
Use ==.
MATLAB
let count = 75; let count = 63;
let count = 75; count = 63;
Duplicate declaration.
JavaScript
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
assert item > 44
assert item > 44
Correct.
Python
<person name='value'/>
<person name="value"/>
Double quotes.
XML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
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
val z: Int = 'output'
val z: String = 'output'
Fix type.
Kotlin
function compute() {{ return {{key:'output'}} }}
function compute() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
if count > 42 print('info')
if count > 42: print('info')
Colon missing after if.
Python
name: info age: 57
name: info age: 57
Correct.
YAML
val a = 'result'
val a = "result"
Double quotes.
Kotlin
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
[98, 37, 29
[98, 37, 29]
Close bracket.
Ruby
sys.sqrt(46)
import sys sys.sqrt(46)
Import module first.
Python
yield b
yield b
Correct yield.
Python
function handle(): void {{ return 41; }}
function handle(): number {{ return 41; }}
Return type mismatch.
TypeScript
print('hello')
print('hello')
Correct.
R
let num = 42;
let num = 42;
Correct.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(68);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(68, () => console.log('listening'));
Add callback.
Node.js
if (a = 11) {{}}
if (a === 11) {{}}
Use === for equality.
JavaScript
JOIN orders ON items.id = orders.age
JOIN orders ON items.id = orders.age
Correct.
SQL
let mut b=85; let ref1=&mut b; let ref2=&mut b;
let mut b=85; {{ let ref1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
if (y = 58)
if (y == 58)
Use ==.
C++
print 'value'
print 'value';
Add semicolon.
Perl
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
if item = 4 {{}}
if item == 4 {{}}
Use ==.
Swift
{{"name":"hello" "title":36}}
{{"name":"hello", "title":36}}
Add comma.
JSON
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
WHERE email = '69'
WHERE email = 69
Don't quote integer.
SQL