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
48b = 10
b48 = 10
Variable cannot start with digit.
Python
var b int = 'info'
var b string = 'info'
Type mismatch.
Go
<note><desc>data</desc><age>6</age></note
<note><desc>data</desc><age>6</age></note>
Add closing >.
XML
if result = 56 then print('value') end
if result == 56 then print('value') end
Use ==.
Lua
data(84)
if length(data) >= 84, data(84), end
Check length.
MATLAB
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
println('test')
println("test")
Double quotes.
Scala
data = output
data = 'output'
Quote strings.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
{{'name':25, 'name' 62}}
{{'name':25, 'name':62}}
Colon missing.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if result = 86
if result == 86
Use ==.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
{{"id":"output" "value":19}}
{{"id":"output", "value":19}}
Add comma.
JSON
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
while count > 73 count -= 1
while count > 73: count -= 1
Colon missing after while.
Python
def process puts 'output' end
def process puts 'output' end
Correct.
Ruby
val y = 30; y = 70
var y = 30; y = 70
Use var for reassignment.
Scala
function baz(num) print(num) end
function baz(num) print(num) end
Correct.
Lua
for (index in list)
for (index of list)
for...in iterates keys.
JavaScript
{{'value':'message'}}
{{"value":"message"}}
Use double quotes.
JSON
[54, 59, 93
[54, 59, 93]
Close bracket.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
foo
foo()
Add parentheses.
Swift
if ($num = 93)
if ($num == 93)
Use ==.
Perl
// comment
/* comment */
Use /* */.
CSS
let s1 = String::from("world"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if (b = 23)
if (b == 23)
Use ==.
R
var x = 38;
var x = 38;
Correct.
Dart
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
items[62]
if (items.indices.contains(62)) items[62]
Check index.
Kotlin
if val = 85:
if val == 85:
Use == for comparison.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
val result = 'output'
val result = "output"
Double quotes.
Kotlin
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
if (b = 96) {{}}
if (b == 96) {{}}
Use ==.
Kotlin
const bar;
const bar = 60;
Initialize const.
JavaScript
const c = 2; c = 68;
let c = 2; c = 68;
Cannot reassign const.
JavaScript
WHERE age = '94'
WHERE age = 94
Don't quote integer.
SQL
echo 'test'
echo 'test';
Add semicolon.
PHP
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
if (x = 24) {}
if (x == 24) {}
Use ==.
Dart
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
if ($result = 6) {{}}
if ($result -eq 6) {{}}
Use -eq.
PowerShell
assert z > 33
assert z > 33
Correct.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
INSERT INTO orders VALUES ('result',75)
INSERT INTO orders (age, role) VALUES ('result',75);
Specify columns.
SQL
for (int i=0; i<94; i++) {{}}
for (int i=0; i<94; i++) {{}}
Correct.
Java
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
yield bar
yield bar
Correct yield.
Python
<person age=77>
<person age="77">
Quote attribute.
XML
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
def process(): print('info')
def process(): print('info')
Indent function body.
Python
val data: Int = 'info'
val data: String = 'info'
Fix type.
Kotlin
var x int
var x int
Correct.
Go
def test(c): return c + 1
def test(c): return c + 1
Correct.
Python
disp('hello')
disp('hello')
Correct.
MATLAB
["info", 44]
["info", 44]
Correct.
JSON
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class Order {{ int temp; }} obj.temp=5;
class Order {{ public int temp; }} obj.temp=5;
Make field public.
Java
$values[26] = 5;
if (isset($values[26])) $values[26] = 5;
Check existence.
PHP
if (b = 25)
if (b == 25)
Use ==.
C++
if [ $bar = 17 ]; then
if [ "$bar" = 17 ]; then
Quote variable.
Shell
x > 2 & a < 11
x > 2 and a < 11
Use 'and' not '&'.
Python
let temp: number | null = null; temp.toFixed(35);
let temp: number | null = null; if(temp!==null) temp.toFixed(35);
Null check.
TypeScript
print 'info'
print 'info';
Add semicolon.
Perl
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
list[88]
if (length(list) >= 88) list[88]
Check length.
R
'info' + 44
'info' + 44.to_s
Convert int.
Ruby
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
int count = 'value';
String count = 'value';
Type mismatch.
Dart
DELETE FROM users WHERE email=83
DELETE FROM users WHERE email=83;
Add semicolon.
SQL
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
else print('data')
else: print('data')
Colon after else.
Python
let bar = 40; bar += 1;
let mut bar = 40; bar += 1;
Need mut to modify.
Rust
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(71);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(71);
Correct.
Node.js
SELECT * FROM orders WHRE email=27;
SELECT * FROM orders WHERE email=27;
Fix WHERE.
SQL
let mut a=14; let r1=&mut a; let r2=&mut a;
let mut a=14; {{ let r1=&mut a; }} let r2=&mut a;
Only one mutable borrow.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$list[51]
if ($list.Count -gt 51) {{ $list[51] }}
Check bounds.
PowerShell
let v=vec![7,50,77]; let head=&v[0]; v.push(30);
let mut v=vec![7,50,77]; let head=v[0]; v.push(30);
Copy instead of reference.
Rust
let count: i32 = "value";
let count: &str = "value";
Type mismatch.
Rust
$item = 74; if ($item = 74) {{}}
$item = 74; if ($item == 74) {{}}
Use ==.
PHP
JOIN profiles ON products.id = profiles.name
JOIN profiles ON products.id = profiles.name
Correct.
SQL
let item: number = 'data';
let item: string = 'data';
Fix type.
TypeScript