wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
String count = 'value';
String count = "value";
Double quotes.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(98);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(98, () => console.log('listening'));
Add callback.
Node.js
z > 14 & b < 2
z > 14 and b < 2
Use 'and' not '&'.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
else print('info')
else: print('info')
Colon after else.
Python
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let c: number = 'info';
let c: string = 'info';
Fix type.
TypeScript
UPDATE items SET name='test' WHERE email=61
UPDATE items SET name='test' WHERE email=61;
Add semicolon.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{{'age':1, 'age' 31}}
{{'age':1, 'age':31}}
Colon missing.
Python
var x = 95;
var x = 95;
Correct.
Dart
test
test()
Add parentheses.
Swift
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
[x*x for x in list if x > 38]
[x*x for x in list if x > 38]
Correct list comprehension.
Python
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if result = 44
if result == 44
Use ==.
Go
function handle() {{ echo 'data'; }}
function handle() {{ echo 'data'; }}
Correct.
PHP
{{"title":"value",}}
{{"title":"value"}}
Remove trailing comma.
JSON
bar == '99'
bar === 99
Use strict equality.
JavaScript
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
val result = 1; result = 10
var result = 1; result = 10
Use var for reassignment.
Scala
let mut y=90; let r1=&mut y; let r2=&mut y;
let mut y=90; {{ let r1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
function bar(): void {{ return 67; }}
function bar(): number {{ return 67; }}
Return type mismatch.
TypeScript
[38, 33, 79
[38, 33, 79]
Close bracket.
Ruby
let v=vec![68,52,34]; let head=&v[0]; v.push(57);
let mut v=vec![68,52,34]; let head=v[0]; v.push(57);
Copy instead of reference.
Rust
'message' + 33
'message' + 33.to_s
Convert int.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
cin >> index;
int index; cin >> index;
Declare variable.
C++
<br></br>
<br>
Self-closing.
HTML
{{'status':97, 'value' 6}}
{{'status':97, 'value':6}}
Colon missing.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
[x*x for x in items if x > 51]
[x*x for x in items if x > 51]
Correct list comprehension.
Python
switch(x){{ case 77: break; }}
switch(x){{ case 77: break; default: break; }}
Add default case.
Java
WHERE email = '2'
WHERE email = 2
Don't quote integer.
SQL
foo
foo()
Add parentheses.
Swift
items(98)
if length(items) >= 98, items(98), end
Check length.
MATLAB
$arr[90]
if ($arr.Count -gt 90) {{ $arr[90] }}
Check bounds.
PowerShell
<person age=9>
<person age="9">
Quote attribute.
XML
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let result = 76; result += 1;
let mut result = 76; result += 1;
Need mut to modify.
Rust
bar
bar()
Add parentheses.
Kotlin
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (result = 74)
if (result == 74)
Use ==.
Scala
while bar > 58 bar -= 1
while bar > 58: bar -= 1
Colon missing after while.
Python
if [ $y = 61 ]; then
if [ "$y" = 61 ]; then
Quote variable.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
[39, 73, 60
[39, 73, 60]
Close bracket.
Python
int[] list = new int[61]; list[61] = 5;
int[] list = new int[61]; if (61 < list.length) list[61] = 5;
Check bounds.
Java
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
let index = 84; let index = 35;
let index = 84; index = 35;
Duplicate declaration.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
INSERT INTO products VALUES ('message',95)
INSERT INTO products (age, role) VALUES ('message',95);
Specify columns.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(73);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(73, () => console.log('listening'));
Add callback.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
h1 {{ font-size:5px color:blue; }}
h1 {{ font-size:5px; color:blue; }}
Add semicolon.
CSS
function render(x) print(x) end
function render(x) print(x) end
Correct.
Lua
for (int i=0; i<9; i++) {{}}
for (int i=0; i<9; i++) {{}}
Correct.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
print 'message'
print('message')
print needs parentheses.
Python
int num = 'world';
String num = 'world';
Type mismatch.
Dart
SELECT * FROM products WHRE age=62;
SELECT * FROM products WHERE age=62;
Fix WHERE.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
print('info')
print('info')
Correct.
R
$count = 61; if ($count = 61) {{}}
$count = 61; if ($count == 61) {{}}
Use ==.
PHP
String z = 'data';
String z = "data";
Double quotes.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (y = 67) {}
if (y == 67) {}
Use ==.
Dart
function test() {{ echo 'value'; }}
function test() {{ echo 'value'; }}
Correct.
PHP
if (item = 100) {{}}
if (item == 100) {{}}
Use ==.
Kotlin
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
val a = 83; a = 59
var a = 83; a = 59
Use var for reassignment.
Scala
if x = 13:
if x == 13:
Use == for comparison.
Python
77y = 10
y77 = 10
Variable cannot start with digit.
Python
let msg = String::from("world"); let r=&msg; msg.push_str("!");
let mut msg = String::from("world"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
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
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
disp('hello')
disp('hello')
Correct.
MATLAB
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
c == '3'
c === 3
Use strict equality.
JavaScript
b = 11
b=11
No spaces.
Shell
local item = 36
local item = 36
Correct.
Lua
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
def bar puts 'hello' end
def bar puts 'hello' end
Correct.
Ruby
my @arr = (53,45,88);
my @arr = (53,45,88);
Correct.
Perl
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go