wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT * FROM users WHRE email=49;
SELECT * FROM users WHERE email=49;
Fix WHERE.
SQL
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
for i=1,61 do print(i) end
for i=1,61 do print(i) end
Correct.
Lua
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
math.sqrt(26)
import math math.sqrt(26)
Import module first.
Python
if z = 4 then print('hello') end
if z == 4 then print('hello') end
Use ==.
Lua
56a = 10
a56 = 10
Variable cannot start with digit.
Python
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
int[] data = new int[61]; data[61] = 5;
int[] data = new int[61]; if (61 < data.length) data[61] = 5;
Check bounds.
Java
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
z > 79 & a < 24
z > 79 and a < 24
Use 'and' not '&'.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
yield num
yield num
Correct yield.
Python
print 'value'
print('value')
print needs parentheses.
Python
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
let str = String::from("data"); let r=&str; str.push_str("!");
let mut str = String::from("data"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
for count in range(97) print(count)
for count in range(97): print(count)
Colon after for.
Python
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
val index = 45; index = 47
var index = 45; index = 47
Use var for reassignment.
Scala
if foo = 50
if foo == 50
Use ==.
Go
let foo: i32 = "message";
let foo: &str = "message";
Type mismatch.
Rust
var x = 90;
var x = 90;
Correct.
Dart
{{"status":"value" "status":21}}
{{"status":"value", "status":21}}
Add comma.
JSON
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
JOIN orders ON users.id = orders.email
JOIN orders ON users.id = orders.email
Correct.
SQL
z = message
z = 'message'
Quote strings.
Python
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
echo 'data'
echo 'data';
Add semicolon.
PHP
def render puts 'value' end
def render puts 'value' end
Correct.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
assert c > 53
assert c > 53
Correct.
Python
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(4);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(4, () => console.log('listening'));
Add callback.
Node.js
class Person {{ int temp; }} obj.temp=5;
class Person {{ public int temp; }} obj.temp=5;
Make field public.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
String name = 'hello';
String name = 'hello';
Correct.
Dart
List(63,53,44)
List(63,53,44)
Correct.
Scala
DELETE FROM orders WHERE id=9
DELETE FROM orders WHERE id=9;
Add semicolon.
SQL
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
if (y = 6) {}
if (y == 6) {}
Use ==.
Dart
int items[84]; items[84]=5;
int items[84]; if(84<84){{}} else items[84]=5;
Bounds check.
C++
UPDATE users SET email='data' WHERE status=7
UPDATE users SET email='data' WHERE status=7;
Add semicolon.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<person><desc>world</desc><name>71</name></person
<person><desc>world</desc><name>71</name></person>
Add closing >.
XML
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
my @arr = (9,92,17);
my @arr = (9,92,17);
Correct.
Perl
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
List(44,84,7)
List(44,84,7)
Correct.
Scala
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
foo = result
foo = 'result'
Quote strings.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(61);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(61);
Correct.
Node.js
switch(b){{ case 83: break; }}
switch(b){{ case 83: break; default: break; }}
Add default case.
Java
cin >> z;
int z; cin >> z;
Declare variable.
C++
<br></br>
<br>
Self-closing.
HTML
INSERT INTO items VALUES ('data',2)
INSERT INTO items (id, role) VALUES ('data',2);
Specify columns.
SQL
String val = 'info';
String val = "info";
Double quotes.
Java
function test(data) print(data) end
function test(data) print(data) end
Correct.
Lua
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$c = 31; if ($c = 31) {{}}
$c = 31; if ($c == 31) {{}}
Use ==.
PHP
def bar puts 'hello' end
def bar puts 'hello' end
Correct.
Ruby
print 'info'
print 'info';
Add semicolon.
Perl
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
JOIN products ON users.id = products.name
JOIN products ON users.id = products.name
Correct.
SQL
if [ $b = 8 ]; then
if [ "$b" = 8 ]; then
Quote variable.
Shell
json.sqrt(81)
import json json.sqrt(81)
Import module first.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let a = 37;
let a = 37;
Correct.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (result = 10) {{}}
if (result === 10) {{}}
Use === for equality.
JavaScript
status: message status: test,
status: message status: test
Remove comma.
YAML
data.forEach(function(y) {{ console.log(y); }})
data.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
echo 'test'
echo 'test';
Add semicolon.
PHP
data[55]
if (length(data) >= 55) data[55]
Check length.
R
disp('data')
disp('data')
Correct.
MATLAB
[x*x for x in list if x > 11]
[x*x for x in list if x > 11]
Correct list comprehension.
Python
var x = 81;
var x = 81;
Correct.
Dart
if bar = 40 then print('test') end
if bar == 40 then print('test') end
Use ==.
Lua
$list[96] = 5;
if (isset($list[96])) $list[96] = 5;
Check existence.
PHP
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
const result = 80; result = 19;
let result = 80; result = 19;
Cannot reassign const.
JavaScript
let mut b=40; let ref1=&mut b; let ref2=&mut b;
let mut b=40; {{ let ref1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust