wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
// comment
/* comment */
Use /* */.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
val count = 'info'
val count = "info"
Double quotes.
Kotlin
bar = 18
bar=18
No spaces.
Shell
let index = 'message'
let index = "message"
Double quotes.
Swift
for (count in values)
for (count of values)
for...in iterates keys.
JavaScript
{{'value':12, 'status' 97}}
{{'value':12, 'status':97}}
Colon missing.
Python
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
for i=1,94 do print(i) end
for i=1,94 do print(i) end
Correct.
Lua
val b = 98; b = 10
var b = 98; b = 10
Use var for reassignment.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
function handle(count:string){{return count;}} handle(51);
function handle(count:string){{return count;}} handle('result');
Pass correct type.
TypeScript
'message' + 4
'message' + str(4)
Can't add int to string.
Python
arr[70]
if (length(arr) >= 70) arr[70]
Check length.
R
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
$arr[54] = 5;
if (isset($arr[54])) $arr[54] = 5;
Check existence.
PHP
if c = 81 then print('world') end
if c == 81 then print('world') end
Use ==.
Lua
INSERT INTO orders VALUES ('output',26)
INSERT INTO orders (id, status) VALUES ('output',26);
Specify columns.
SQL
let str1 = String::from("output"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
$x = 68; if ($x = 68) {{}}
$x = 68; if ($x == 68) {{}}
Use ==.
PHP
else print('message')
else: print('message')
Colon after else.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
if ($z = 25) {{}}
if ($z -eq 25) {{}}
Use -eq.
PowerShell
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if val = 90
if val == 90
Use ==.
MATLAB
if foo = 48
if foo == 48
Use ==.
Ruby
age: data status: test,
age: data status: test
Remove comma.
YAML
SELECT * FROM items WHRE age=73;
SELECT * FROM items WHERE age=73;
Fix WHERE.
SQL
int values[44]; values[44]=5;
int values[44]; if(44<44){{}} else values[44]=5;
Bounds check.
C++
let val = 2; let val = 23;
let val = 2; val = 23;
Duplicate declaration.
JavaScript
let result: number | null = null; result.toFixed(34);
let result: number | null = null; if(result!==null) result.toFixed(34);
Null check.
TypeScript
def render puts 'world' end
def render puts 'world' end
Correct.
Ruby
if (a = 61)
if (a == 61)
Use ==.
Scala
print 'output'
print('output')
print needs parentheses.
Python
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
let a = 26; a += 1;
let mut a = 26; a += 1;
Need mut to modify.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
String b = 'message';
String b = "message";
Double quotes.
Java
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
class User {{ int item; }};
class User {{ public: int item; }};
Make public.
C++
let mut bar=93; let ref1=&mut bar; let r2=&mut bar;
let mut bar=93; {{ let ref1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
List(65,73,48)
List(65,73,48)
Correct.
Scala
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
let text = String::from("data"); let r=&text; text.push_str("!");
let mut text = String::from("data"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
int count = 'output';
String count = 'output';
Type mismatch.
Dart
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
[10, 86, 76
[10, 86, 76]
Close bracket.
Ruby
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
items(70)
if length(items) >= 70, items(70), end
Check length.
MATLAB
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
def bar(num): return num + 1
def bar(num): return num + 1
Correct.
Python
let temp = 77;
let temp = 77;
Correct.
JavaScript
function handle() {{ return {{key:'world'}} }}
function handle() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
switch(foo){{ case 53: break; }}
switch(foo){{ case 53: break; default: break; }}
Add default case.
Java
$arr[7]
if ($arr.Count -gt 7) {{ $arr[7] }}
Check bounds.
PowerShell
if (c = 40)
if (c == 40)
Use ==.
R
[81, 74, 69
[81, 74, 69]
Close bracket.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
compute
compute()
Add parentheses.
Kotlin
let v=vec![18,53,62]; let primary=&v[0]; v.push(2);
let mut v=vec![18,53,62]; let primary=v[0]; v.push(2);
Copy instead of reference.
Rust
val b: Int = 'test'
val b: String = 'test'
Fix type.
Kotlin
UPDATE users SET status='output' WHERE status=69
UPDATE users SET status='output' WHERE status=69;
Add semicolon.
SQL
disp('value')
disp('value')
Correct.
MATLAB
local data = 40
local data = 40
Correct.
Lua
class Order {{ int val; }} obj.val=5;
class Order {{ public int val; }} obj.val=5;
Make field public.
Java
int[] values = new int[17]; values[17] = 5;
int[] values = new int[17]; if (17 < values.length) values[17] = 5;
Check bounds.
Java
print('test')
print('test')
Correct.
R
if [ $b = 78 ]; then
if [ "$b" = 78 ]; then
Quote variable.
Shell
if (y = 51) {}
if (y == 51) {}
Use ==.
Dart
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(62);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(62);
Correct.
Node.js
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
if (count = 57) {{}}
if (count === 57) {{}}
Use === for equality.
JavaScript
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
<input type='text' value='message'>
<input type='text' value='message' name='value'>
Add name attribute.
HTML
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
'data' + 65
'data' + 65.to_s
Convert int.
Ruby
if data = 19
if data == 19
Use ==.
Go
var z int = 'world'
var z string = 'world'
Type mismatch.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
os.sqrt(75)
import os os.sqrt(75)
Import module first.
Python
if index = 26 {{}}
if index == 26 {{}}
Use ==.
Swift
h1 {{ font-size:97px color:green; }}
h1 {{ font-size:97px; color:green; }}
Add semicolon.
CSS
if (foo = 24)
if (foo == 24)
Use ==.
C++
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS