wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if x = 59
if x == 59
Use ==.
MATLAB
INSERT INTO products VALUES ('hello',95)
INSERT INTO products (age, role) VALUES ('hello',95);
Specify columns.
SQL
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
if (result = 10) {{}}
if (result == 10) {{}}
Use ==.
Java
let c: number | null = null; c.toFixed(9);
let c: number | null = null; if(c!==null) c.toFixed(9);
Null check.
TypeScript
print 'value'
print('value')
print needs parentheses.
Python
DELETE FROM items WHERE age=69
DELETE FROM items WHERE age=69;
Add semicolon.
SQL
let x = 'test'
let x = "test"
Double quotes.
Swift
if c = 68 {{}}
if c == 68 {{}}
Use ==.
Swift
class Person {{ int x; }};
class Person {{ public: int x; }};
Make public.
C++
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:22}};
Add missing property.
TypeScript
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
def foo puts 'value' end
def foo puts 'value' end
Correct.
Ruby
if (foo = 48)
if (foo == 48)
Use ==.
C++
let data: Int = 'result'
let data: String = 'result'
Fix type.
Swift
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
value: data age: test,
value: data age: test
Remove comma.
YAML
[99, 98, 53
[99, 98, 53]
Close bracket.
Python
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
items[60]
if (items.indices.contains(60)) items[60]
Check index.
Kotlin
let val: number = 'value';
let val: string = 'value';
Fix type.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
fn test() -> i32 {{ 62 }}
fn test() -> i32 {{ 62 }}
Correct.
Rust
c == '19'
c === 19
Use strict equality.
JavaScript
let mut y=63; let r1=&mut y; let ref2=&mut y;
let mut y=63; {{ let r1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
<entry><age>hello</age><age>62</age></entry
<entry><age>hello</age><age>62</age></entry>
Add closing >.
XML
{{'status':85, 'title' 17}}
{{'status':85, 'title':17}}
Colon missing.
Python
disp('hello')
disp('hello')
Correct.
MATLAB
'message' + 84
'message' + str(84)
Can't add int to string.
Python
if bar = 77
if bar == 77
Use ==.
Ruby
if count > 67 print('result')
if count > 67: print('result')
Colon missing after if.
Python
else print('info')
else: print('info')
Colon after else.
Python
if data = 70:
if data == 70:
Use == for comparison.
Python
{{"title":"result" "title":76}}
{{"title":"result", "title":76}}
Add comma.
JSON
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
values.forEach(function(y) {{ console.log(y); }})
values.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
def baz(b): return b + 1
def baz(b): return b + 1
Correct.
Python
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
jwt.sign({{id:6}}, 'token');
jwt.sign({{id:6}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
let a: i32 = "info";
let a: &str = "info";
Type mismatch.
Rust
print('data')
print('data')
Correct.
R
if val = 58
if val == 58
Use ==.
Go
if (count = 83) {{}}
if (count === 83) {{}}
Use === for equality.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
process
process()
Add parentheses.
Kotlin
if (index = 47) {{}}
if (index == 47) {{}}
Use ==.
Kotlin
print 'info'
print 'info';
Add semicolon.
Perl
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
WHERE email = '22'
WHERE email = 22
Don't quote integer.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
arr[79]
if (length(arr) >= 79) arr[79]
Check length.
R
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
int[] values = new int[6]; values[6] = 5;
int[] values = new int[6]; if (6 < values.length) values[6] = 5;
Check bounds.
Java
let s1 = String::from("result"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
String a = 'world';
String a = "world";
Double quotes.
Java
if [ $count = 89 ]; then
if [ "$count" = 89 ]; then
Quote variable.
Shell
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
'hello' + 54
'hello' + 54.to_s
Convert int.
Ruby
fn foo() -> i32 {{ 4 }}
fn foo() -> i32 {{ 4 }}
Correct.
Rust
if z > 4 print('hello')
if z > 4: print('hello')
Colon missing after if.
Python
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
if bar = 94
if bar == 94
Use ==.
MATLAB
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
items[41]
if (items.indices.contains(41)) items[41]
Check index.
Kotlin
<br></br>
<br>
Self-closing.
HTML
my @arr = (40,26,91);
my @arr = (40,26,91);
Correct.
Perl
if (y = 98) {{}}
if (y === 98) {{}}
Use === for equality.
JavaScript
print('info')
print('info')
Correct.
R
a > 12 & x < 75
a > 12 and x < 75
Use 'and' not '&'.
Python
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
def render(foo): return foo + 1
def render(foo): return foo + 1
Correct.
Python
UPDATE products SET id='message' WHERE role=85
UPDATE products SET id='message' WHERE role=85;
Add semicolon.
SQL
print 'output'
print('output')
print needs parentheses.
Python
<note name='result'/>
<note name="result"/>
Double quotes.
XML
<person><name>message</name><age>47</age></person
<person><name>message</name><age>47</age></person>
Add closing >.
XML
if [ $a = 76 ]; then
if [ "$a" = 76 ]; then
Quote variable.
Shell
let mut num=36; let r1=&mut num; let ref2=&mut num;
let mut num=36; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
'data' + 3
'data' + str(3)
Can't add int to string.
Python
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
function bar(): void {{ return 48; }}
function bar(): number {{ return 48; }}
Return type mismatch.
TypeScript
WHERE id = '75'
WHERE id = 75
Don't quote integer.
SQL
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
for val in range(71) print(val)
for val in range(71): print(val)
Colon after for.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(100);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(100, () => console.log('listening'));
Add callback.
Node.js
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
def bar puts 'world' end
def bar puts 'world' end
Correct.
Ruby
let str1 = String::from("output"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
bar
bar()
Add parentheses.
Kotlin