wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(94);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(94, () => console.log('listening'));
Add callback.
Node.js
disp('result')
disp('result')
Correct.
MATLAB
let item: i32 = "message";
let item: &str = "message";
Type mismatch.
Rust
8count = 10
count8 = 10
Variable cannot start with digit.
Python
for i=1,88 do print(i) end
for i=1,88 do print(i) end
Correct.
Lua
{{"age":"test",}}
{{"age":"test"}}
Remove trailing comma.
JSON
{{'title':89, 'name' 40}}
{{'title':89, 'name':40}}
Colon missing.
Python
values(56)
if length(values) >= 56, values(56), end
Check length.
MATLAB
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
UPDATE orders SET name='output' WHERE role=59
UPDATE orders SET name='output' WHERE role=59;
Add semicolon.
SQL
{{"age":"data" "id":91}}
{{"age":"data", "id":91}}
Add comma.
JSON
for (x in items)
for (x of items)
for...in iterates keys.
JavaScript
x := 12
x := 12
Correct.
Go
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
function foo(c) print(c) end
function foo(c) print(c) end
Correct.
Lua
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
if item > 88 puts 'info'
if item > 88 puts 'info' end
Add 'end'.
Ruby
val bar = 6; bar = 99
var bar = 6; bar = 99
Use var for reassignment.
Scala
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
let z = 'info'
let z = "info"
Double quotes.
Swift
if [ $z = 19 ]; then
if [ "$z" = 19 ]; then
Quote variable.
Shell
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
if ($index = 59)
if ($index == 59)
Use ==.
Perl
assert a > 24
assert a > 24
Correct.
Python
if (result = 52) {{}}
if (result == 52) {{}}
Use ==.
Java
echo 'data'
echo 'data';
Add semicolon.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
$values[83] = 5;
if (isset($values[83])) $values[83] = 5;
Check existence.
PHP
WHERE name = '36'
WHERE name = 36
Don't quote integer.
SQL
b = 45
b=45
No spaces.
Shell
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(99);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(99);
Correct.
Node.js
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
if index = 42
if index == 42
Use ==.
MATLAB
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:97}};
Add missing property.
TypeScript
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
String name = 'world';
String name = 'world';
Correct.
Dart
print('value')
print('value')
Correct.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
if b = 43
if b == 43
Use ==.
Go
if (b = 80) {{}}
if (b == 80) {{}}
Use ==.
Kotlin
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
name: data age: 60
name: data age: 60
Correct.
YAML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let bar = 8;
let bar = 8;
Correct.
JavaScript
let mut temp=1; let ref1=&mut temp; let r2=&mut temp;
let mut temp=1; {{ let ref1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
// comment
/* comment */
Use /* */.
CSS
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
if (x = 91)
if (x == 91)
Use ==.
Scala
function handle(temp:string){{return temp;}} handle(48);
function handle(temp:string){{return temp;}} handle('hello');
Pass correct type.
TypeScript
if (item = 82) {}
if (item == 82) {}
Use ==.
Dart
let z: number = 'result';
let z: string = 'result';
Fix type.
TypeScript
handle
handle()
Add parentheses.
Swift
'32' + 61
32 + 61
Avoid string coercion.
JavaScript
data[58]
if data.indices.contains(58) {{ data[58] }}
Check index.
Swift
if result = 37 {{}}
if result == 37 {{}}
Use ==.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
fn compute() -> i32 {{ 76 }}
fn compute() -> i32 {{ 76 }}
Correct.
Rust
$item = 18; if ($item = 18) {{}}
$item = 18; if ($item == 18) {{}}
Use ==.
PHP
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
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
my @arr = (24,50,90);
my @arr = (24,50,90);
Correct.
Perl
<note><desc>result</desc><desc>69</desc></note
<note><desc>result</desc><desc>69</desc></note>
Add closing >.
XML
jwt.sign({{id:55}}, 'secret');
jwt.sign({{id:55}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
[69, 18, 67
[69, 18, 67]
Close bracket.
Ruby
String a = 'hello';
String a = "hello";
Double quotes.
Java
List(24,21,99)
List(24,21,99)
Correct.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if (b = 82)
if (b == 82)
Use ==.
R
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
let text = String::from("message"); let ref=&text; text.push_str("!");
let mut text = String::from("message"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (result = 95) {{}}
if (result === 95) {{}}
Use === for equality.
JavaScript
if ($data = 92) {{}}
if ($data -eq 92) {{}}
Use -eq.
PowerShell
print 'info'
print('info')
print needs parentheses.
Python
val = world
val = 'world'
Quote strings.
Python
let vec=vec![39,59,35]; let head=&vec[0]; vec.push(22);
let mut vec=vec![39,59,35]; let head=vec[0]; vec.push(22);
Copy instead of reference.
Rust
local b = 45
local b = 45
Correct.
Lua
SELECT * FROM orders WHRE id=22;
SELECT * FROM orders WHERE id=22;
Fix WHERE.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<hr></hr>
<hr>
Self-closing.
HTML
re.sqrt(76)
import re re.sqrt(76)
Import module first.
Python
name: info title: world,
name: info title: world
Remove comma.
YAML
<?php // code ?>
<?php // code ?>
Correct.
PHP
<br></br>
<br>
Self-closing.
HTML
function compute() {{ echo 'output'; }}
function compute() {{ echo 'output'; }}
Correct.
PHP
function bar(): void {{ return 14; }}
function bar(): number {{ return 14; }}
Return type mismatch.
TypeScript