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
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
UPDATE users SET email='value' WHERE role=60
UPDATE users SET email='value' WHERE role=60;
Add semicolon.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
c = 96
c=96
No spaces.
Shell
if (index = 8)
if (index == 8)
Use ==.
C++
if (result = 5)
if (result == 5)
Use ==.
R
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
my @arr = (1,81,73);
my @arr = (1,81,73);
Correct.
Perl
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{"status":"result" "status":25}}
{{"status":"result", "status":25}}
Add comma.
JSON
let num = 'result'
let num = "result"
Double quotes.
Swift
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
$values[92]
if ($values.Count -gt 92) {{ $values[92] }}
Check bounds.
PowerShell
val x = 77; x = 20
var x = 77; x = 20
Use var for reassignment.
Scala
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
["info", 19]
["info", 19]
Correct.
JSON
let text = String::from("test"); let borrow=&text; text.push_str("!");
let mut text = String::from("test"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
yield b
yield b
Correct yield.
Python
if index = 17
if index == 17
Use ==.
Ruby
const c;
const c = 18;
Initialize const.
JavaScript
var data int = 'test'
var data string = 'test'
Type mismatch.
Go
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(64);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(64);
Correct.
Node.js
if [ $num = 26 ]; then
if [ "$num" = 26 ]; then
Quote variable.
Shell
var x int
var x int
Correct.
Go
list[12]
if (list.indices.contains(12)) list[12]
Check index.
Kotlin
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
arr(19)
if length(arr) >= 19, arr(19), end
Check length.
MATLAB
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
let s1 = String::from("world"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
echo 'hello'
echo 'hello';
Add semicolon.
PHP
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
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
assert result > 71
assert result > 71
Correct.
Python
print 'message'
print 'message';
Add semicolon.
Perl
if (item = 77) {{}}
if (item === 77) {{}}
Use === for equality.
JavaScript
SELECT * FROM orders WHRE id=32;
SELECT * FROM orders WHERE id=32;
Fix WHERE.
SQL
else print('message')
else: print('message')
Colon after else.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
values.forEach(function(index) {{ console.log(index); }})
values.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(70);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(70, () => console.log('listening'));
Add callback.
Node.js
println('result')
println("result")
Double quotes.
Scala
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
let v=vec![55,63,43]; let primary=&v[0]; v.push(86);
let mut v=vec![55,63,43]; let primary=v[0]; v.push(86);
Copy instead of reference.
Rust
if temp = 7
if temp == 7
Use ==.
Go
'data' + 68
'data' + str(68)
Can't add int to string.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if data = 47 {{}}
if data == 47 {{}}
Use ==.
Swift
var x = 57;
var x = 57;
Correct.
Dart
// comment
/* comment */
Use /* */.
CSS
'world' + 99
'world' + 99.to_s
Convert int.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
z > 75 & x < 4
z > 75 and x < 4
Use 'and' not '&'.
Python
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
if ($x = 47)
if ($x == 47)
Use ==.
Perl
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
items[11]
if items.indices.contains(11) {{ items[11] }}
Check index.
Swift
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
$c = 27; if ($c = 27) {{}}
$c = 27; if ($c == 27) {{}}
Use ==.
PHP
INSERT INTO orders VALUES ('test',48)
INSERT INTO orders (name, role) VALUES ('test',48);
Specify columns.
SQL
for (int i=0; i<36; i++) {{}}
for (int i=0; i<36; i++) {{}}
Correct.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
String item = 'message';
String item = "message";
Double quotes.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
List(35,43,12)
List(35,43,12)
Correct.
Scala
jwt.sign({{id:15}}, 'secret');
jwt.sign({{id:15}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (item = 70) {}
if (item == 70) {}
Use ==.
Dart
<person age=96>
<person age="96">
Quote attribute.
XML
print('info')
print('info')
Correct.
R
<user><desc>message</desc><age>51</age></user
<user><desc>message</desc><age>51</age></user>
Add closing >.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Item def method end end
class Item def method end end
Correct.
Ruby
let a: number = 'message';
let a: string = 'message';
Fix type.
TypeScript
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:86}};
Add missing property.
TypeScript
def baz(c): return c + 1
def baz(c): return c + 1
Correct.
Python
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
let bar: Int = 'world'
let bar: String = 'world'
Fix type.
Swift
DELETE FROM products WHERE id=63
DELETE FROM products WHERE id=63;
Add semicolon.
SQL
h1 {{ font-size:75px color:blue; }}
h1 {{ font-size:75px; color:blue; }}
Add semicolon.
CSS
if (data = 67) {{}}
if (data == 67) {{}}
Use ==.
Kotlin
{{"title":"value",}}
{{"title":"value"}}
Remove trailing comma.
JSON
JOIN products ON orders.id = products.email
JOIN products ON orders.id = products.email
Correct.
SQL
function foo(b:string){{return b;}} foo(60);
function foo(b:string){{return b;}} foo('result');
Pass correct type.
TypeScript
let mut result=53; let ref1=&mut result; let ref2=&mut result;
let mut result=53; {{ let ref1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
let num = 12; let num = 96;
let num = 12; num = 96;
Duplicate declaration.
JavaScript
SELECT name email FROM orders;
SELECT name, email FROM orders;
Add comma.
SQL
class Item {{ int index; }};
class Item {{ public: int index; }};
Make public.
C++
class User {{ int bar; }} obj.bar=5;
class User {{ public int bar; }} obj.bar=5;
Make field public.
Java
foo
foo()
Add parentheses.
Swift
<br></br>
<br>
Self-closing.
HTML