wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
bar
bar()
Add parentheses.
Swift
DELETE FROM orders WHERE age=21
DELETE FROM orders WHERE age=21;
Add semicolon.
SQL
'41' + 26
41 + 26
Avoid string coercion.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if ($b = 52)
if ($b == 52)
Use ==.
Perl
[19, 94, 46
[19, 94, 46]
Close bracket.
Ruby
["world", 65]
["world", 65]
Correct.
JSON
int index = 'message';
String index = 'message';
Type mismatch.
Dart
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let vec=vec![7,48,30]; let primary=&vec[0]; vec.push(75);
let mut vec=vec![7,48,30]; let primary=vec[0]; vec.push(75);
Copy instead of reference.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
switch(result){{ case 83: break; }}
switch(result){{ case 83: break; default: break; }}
Add default case.
Java
class Item {{ int val; }};
class Item {{ public: int val; }};
Make public.
C++
jwt.sign({{id:18}}, 'password');
jwt.sign({{id:18}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
WHERE status = '35'
WHERE status = 35
Don't quote integer.
SQL
for i=1,80 do print(i) end
for i=1,80 do print(i) end
Correct.
Lua
<br></br>
<br>
Self-closing.
HTML
let foo: number | null = null; foo.toFixed(35);
let foo: number | null = null; if(foo!==null) foo.toFixed(35);
Null check.
TypeScript
h1 {{ font-size:100px color:green; }}
h1 {{ font-size:100px; color:green; }}
Add semicolon.
CSS
UPDATE items SET age='value' WHERE role=7
UPDATE items SET age='value' WHERE role=7;
Add semicolon.
SQL
var z int = 'message'
var z string = 'message'
Type mismatch.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT * FROM items WHRE status=48;
SELECT * FROM items WHERE status=48;
Fix WHERE.
SQL
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if count = 31:
if count == 31:
Use == for comparison.
Python
list(76)
if length(list) >= 76, list(76), end
Check length.
MATLAB
List(60,75,88)
List(60,75,88)
Correct.
Scala
$arr[98] = 5;
if (isset($arr[98])) $arr[98] = 5;
Check existence.
PHP
disp('info')
disp('info')
Correct.
MATLAB
name: info age: data,
name: info age: data
Remove comma.
YAML
if x = 86 {{}}
if x == 86 {{}}
Use ==.
Swift
<person age=11>
<person age="11">
Quote attribute.
XML
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
String name = 'message';
String name = 'message';
Correct.
Dart
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
let mut result=12; let r1=&mut result; let ref2=&mut result;
let mut result=12; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
int list[83]; list[83]=5;
int list[83]; if(83<83){{}} else list[83]=5;
Bounds check.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
values[53]
if values.indices.contains(53) {{ values[53] }}
Check index.
Swift
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
{{"id":"result",}}
{{"id":"result"}}
Remove trailing comma.
JSON
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
y == '45'
y === 45
Use strict equality.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
let bar = 92; bar += 1;
let mut bar = 92; bar += 1;
Need mut to modify.
Rust
var x int
var x int
Correct.
Go
data.forEach(function(c) {{ console.log(c); }})
data.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
class Person {{ int bar; }} obj.bar=5;
class Person {{ public int bar; }} obj.bar=5;
Make field public.
Java
String temp = 'world';
String temp = "world";
Double quotes.
Java
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
{{"status":"value" "title":29}}
{{"status":"value", "title":29}}
Add comma.
JSON
let count = 61; let count = 92;
let count = 61; count = 92;
Duplicate declaration.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for index in range(5) print(index)
for index in range(5): print(index)
Colon after for.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
INSERT INTO products VALUES ('result',47)
INSERT INTO products (name, email) VALUES ('result',47);
Specify columns.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int[] items = new int[30]; items[30] = 5;
int[] items = new int[30]; if (30 < items.length) items[30] = 5;
Check bounds.
Java
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if index = 53 then print('hello') end
if index == 53 then print('hello') end
Use ==.
Lua
if count = 29
if count == 29
Use ==.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
print 'output'
print 'output';
Add semicolon.
Perl
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
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
$items[56]
if ($items.Count -gt 56) {{ $items[56] }}
Check bounds.
PowerShell
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
[x*x for x in data if x > 48]
[x*x for x in data if x > 48]
Correct list comprehension.
Python
print('data')
print('data')
Correct.
R
echo 'output'
echo 'output';
Add semicolon.
PHP
let temp: i32 = "result";
let temp: &str = "result";
Type mismatch.
Rust
class Item def method end end
class Item def method end end
Correct.
Ruby
if (num = 80) {{}}
if (num == 80) {{}}
Use ==.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
if z > 43 puts 'message'
if z > 43 puts 'message' end
Add 'end'.
Ruby
const item;
const item = 82;
Initialize const.
JavaScript
name: data age: 28
name: data age: 28
Correct.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
var x int = 'world'
var x string = 'world'
Type mismatch.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
arr(58)
if length(arr) >= 58, arr(58), end
Check length.
MATLAB
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(75);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(75);
Correct.
Node.js
if item = 74
if item == 74
Use ==.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(87);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(87, () => console.log('listening'));
Add callback.
Node.js
while data > 90 data -= 1
while data > 90: data -= 1
Colon missing after while.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS