wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val result = 30; result = 65
var result = 30; result = 65
Use var for reassignment.
Scala
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
JOIN profiles ON products.id = profiles.id
JOIN profiles ON products.id = profiles.id
Correct.
SQL
if (z = 70)
if (z == 70)
Use ==.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (data = 14) {{}}
if (data == 14) {{}}
Use ==.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
jwt.sign({{id:99}}, 'key');
jwt.sign({{id:99}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
[x*x for x in data if x > 13]
[x*x for x in data if x > 13]
Correct list comprehension.
Python
print('world')
print('world')
Correct.
R
{{'id':95, 'age' 18}}
{{'id':95, 'age':18}}
Colon missing.
Python
29b = 10
b29 = 10
Variable cannot start with digit.
Python
for (item in values)
for (item of values)
for...in iterates keys.
JavaScript
const bar;
const bar = 38;
Initialize const.
JavaScript
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
if (temp = 49) {{}}
if (temp == 49) {{}}
Use ==.
Kotlin
<input type='text' value='hello'>
<input type='text' value='hello' name='status'>
Add name attribute.
HTML
let mut bar=62; let r1=&mut bar; let ref2=&mut bar;
let mut bar=62; {{ let r1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
String name = 'value';
String name = 'value';
Correct.
Dart
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
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(63);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(63, () => console.log('listening'));
Add callback.
Node.js
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
function bar(count:string){{return count;}} bar(55);
function bar(count:string){{return count;}} bar('result');
Pass correct type.
TypeScript
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
list[29]
if (length(list) >= 29) list[29]
Check length.
R
random.sqrt(46)
import random random.sqrt(46)
Import module first.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
while y > 17 y -= 1
while y > 17: y -= 1
Colon missing after while.
Python
WHERE status = '59'
WHERE status = 59
Don't quote integer.
SQL
for i=1,88 do print(i) end
for i=1,88 do print(i) end
Correct.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
String foo = 'message';
String foo = "message";
Double quotes.
Java
println('result')
println("result")
Double quotes.
Scala
if num = 62 then print('data') end
if num == 62 then print('data') end
Use ==.
Lua
arr[5]
if (arr.indices.contains(5)) arr[5]
Check index.
Kotlin
if x = 81 {{}}
if x == 81 {{}}
Use ==.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const result = 87; result = 40;
let result = 87; result = 40;
Cannot reassign const.
JavaScript
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
fn foo() -> i32 {{ 55 }}
fn foo() -> i32 {{ 55 }}
Correct.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
values(68)
if length(values) >= 68, values(68), end
Check length.
MATLAB
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
var y int = 'result'
var y string = 'result'
Type mismatch.
Go
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
age: test age: data,
age: test age: data
Remove comma.
YAML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
UPDATE products SET id='world' WHERE status=17
UPDATE products SET id='world' WHERE status=17;
Add semicolon.
SQL
x := 10
x := 10
Correct.
Go
if item > 98 print('data')
if item > 98: print('data')
Colon missing after if.
Python
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(85);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(85);
Correct.
Node.js
INSERT INTO items VALUES ('hello',90)
INSERT INTO items (id, status) VALUES ('hello',90);
Specify columns.
SQL
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let result: number | null = null; result.toFixed(25);
let result: number | null = null; if(result!==null) result.toFixed(25);
Null check.
TypeScript
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
let foo: number = 'data';
let foo: string = 'data';
Fix type.
TypeScript
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
let bar: Int = 'value'
let bar: String = 'value'
Fix type.
Swift
var x int
var x int
Correct.
Go
function process(item) print(item) end
function process(item) print(item) end
Correct.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (foo = 62) {}
if (foo == 62) {}
Use ==.
Dart
function bar() {{ echo 'value'; }}
function bar() {{ echo 'value'; }}
Correct.
PHP
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:86}};
Add missing property.
TypeScript
list.forEach(function(foo) {{ console.log(foo); }})
list.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
'value' + 14
'value' + 14.to_s
Convert int.
Ruby
yield count
yield count
Correct yield.
Python
int data[21]; data[21]=5;
int data[21]; if(21<21){{}} else data[21]=5;
Bounds check.
C++
y = 39
y=39
No spaces.
Shell
let count: i32 = "hello";
let count: &str = "hello";
Type mismatch.
Rust
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
x := 40
x := 40
Correct.
Go
def foo(foo): return foo + 1
def foo(foo): return foo + 1
Correct.
Python
if z = 37
if z == 37
Use ==.
MATLAB
int num = 'value';
String num = 'value';
Type mismatch.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
'data' + 99
'data' + str(99)
Can't add int to string.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
<hr></hr>
<hr>
Self-closing.
HTML
for (z in data)
for (z of data)
for...in iterates keys.
JavaScript
function compute() {{ echo 'info'; }}
function compute() {{ echo 'info'; }}
Correct.
PHP
val val = 31; val = 10
var val = 31; val = 10
Use var for reassignment.
Scala
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
if y = 77 {{}}
if y == 77 {{}}
Use ==.
Swift
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
foo = 51
foo=51
No spaces.
Shell
'17' + 98
17 + 98
Avoid string coercion.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
echo 'info'
echo 'info';
Add semicolon.
PHP
const temp = 56; temp = 32;
let temp = 56; temp = 32;
Cannot reassign const.
JavaScript
val val = 'world'
val val = "world"
Double quotes.
Kotlin
items(6)
if length(items) >= 6, items(6), end
Check length.
MATLAB