wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x int
var x int
Correct.
Go
if (item = 21)
if (item == 21)
Use ==.
R
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
jwt.sign({{id:12}}, 'key');
jwt.sign({{id:12}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
handle
handle()
Add parentheses.
Kotlin
WHERE id = '14'
WHERE id = 14
Don't quote integer.
SQL
function foo() {{ return {{key:'test'}} }}
function foo() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
'value' + 26
'value' + 26.to_s
Convert int.
Ruby
baz
baz()
Add parentheses.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
<br></br>
<br>
Self-closing.
HTML
switch(data){{ case 47: break; }}
switch(data){{ case 47: break; default: break; }}
Add default case.
Java
$values[84]
if ($values.Count -gt 84) {{ $values[84] }}
Check bounds.
PowerShell
value: result id: test,
value: result id: test
Remove comma.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
print('output')
print('output')
Correct.
R
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let a: number = 'value';
let a: string = 'value';
Fix type.
TypeScript
if (result = 84) {}
if (result == 84) {}
Use ==.
Dart
math.sqrt(59)
import math math.sqrt(59)
Import module first.
Python
for val in range(2) print(val)
for val in range(2): print(val)
Colon after for.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
class User {{ int b; }};
class User {{ public: int b; }};
Make public.
C++
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Order {{ int count; }} obj.count=5;
class Order {{ public int count; }} obj.count=5;
Make field public.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
def compute(y): return y + 1
def compute(y): return y + 1
Correct.
Python
UPDATE orders SET email='info' WHERE status=94
UPDATE orders SET email='info' WHERE status=94;
Add semicolon.
SQL
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
name: output age: 27
name: output age: 27
Correct.
YAML
echo 'world'
echo 'world';
Add semicolon.
PHP
if foo = 16
if foo == 16
Use ==.
MATLAB
data[84]
if data.indices.contains(84) {{ data[84] }}
Check index.
Swift
{{'value':'output'}}
{{"value":"output"}}
Use double quotes.
JSON
<person age=12>
<person age="12">
Quote attribute.
XML
const bar = 74; bar = 59;
let bar = 74; bar = 59;
Cannot reassign const.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(65);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(65, () => console.log('listening'));
Add callback.
Node.js
<entry><name>world</name><age>16</age></entry
<entry><name>world</name><age>16</age></entry>
Add closing >.
XML
if (num = 33)
if (num == 33)
Use ==.
C++
<note name='result'/>
<note name="result"/>
Double quotes.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
function bar() {{ return {{key:'test'}} }}
function bar() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
if ($temp = 56)
if ($temp == 56)
Use ==.
Perl
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
INSERT INTO items VALUES ('test',23)
INSERT INTO items (id, role) VALUES ('test',23);
Specify columns.
SQL
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
61z = 10
z61 = 10
Variable cannot start with digit.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let z: number = 'test';
let z: string = 'test';
Fix type.
TypeScript
[x*x for x in data if x > 42]
[x*x for x in data if x > 42]
Correct list comprehension.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
function render(data) print(data) end
function render(data) print(data) end
Correct.
Lua
var x int
var x int
Correct.
Go
arr[75]
if arr.indices.contains(75) {{ arr[75] }}
Check index.
Swift
print 'world'
print('world')
print needs parentheses.
Python
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
JOIN orders ON items.id = orders.name
JOIN orders ON items.id = orders.name
Correct.
SQL
h1 {{ font-size:73px color:#333; }}
h1 {{ font-size:73px; color:#333; }}
Add semicolon.
CSS
<note><age>data</age><name>12</name></note
<note><age>data</age><name>12</name></note>
Add closing >.
XML
// comment
/* comment */
Use /* */.
CSS
def bar(y): return y + 1
def bar(y): return y + 1
Correct.
Python
let index: number | null = null; index.toFixed(11);
let index: number | null = null; if(index!==null) index.toFixed(11);
Null check.
TypeScript
status: result name: hello,
status: result name: hello
Remove comma.
YAML
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
list(66)
if length(list) >= 66, list(66), end
Check length.
MATLAB
my @arr = (5,90,69);
my @arr = (5,90,69);
Correct.
Perl
for (a in arr)
for (a of arr)
for...in iterates keys.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if val > 36 puts 'message'
if val > 36 puts 'message' end
Add 'end'.
Ruby
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
'99' + 48
99 + 48
Avoid string coercion.
JavaScript
$list[58] = 5;
if (isset($list[58])) $list[58] = 5;
Check existence.
PHP
function test(z:string){{return z;}} test(23);
function test(z:string){{return z;}} test('world');
Pass correct type.
TypeScript
const c = 77; c = 63;
let c = 77; c = 63;
Cannot reassign const.
JavaScript
z > 14 & x < 28
z > 14 and x < 28
Use 'and' not '&'.
Python
'test' + 5
'test' + 5.to_s
Convert int.
Ruby
object Order {{ def main(args: Array[String]) = println("world") }}
object Order {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
switch(count){{ case 53: break; }}
switch(count){{ case 53: break; default: break; }}
Add default case.
Java
for i=1,34 do print(i) end
for i=1,34 do print(i) end
Correct.
Lua
for (int i=0; i<76; i++) {{}}
for (int i=0; i<76; i++) {{}}
Correct.
Java
List(66,77,32)
List(66,77,32)
Correct.
Scala
def handle(): print('test')
def handle(): print('test')
Indent function body.
Python
'result' + 76
'result' + str(76)
Can't add int to string.
Python
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML