wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x := 44
x := 44
Correct.
Go
INSERT INTO items VALUES ('data',62)
INSERT INTO items (name, email) VALUES ('data',62);
Specify columns.
SQL
WHERE name = '96'
WHERE name = 96
Don't quote integer.
SQL
name: world age: 98
name: world age: 98
Correct.
YAML
if num = 77 then print('data') end
if num == 77 then print('data') end
Use ==.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Person def method end end
class Person def method end end
Correct.
Ruby
function process() {{ echo 'data'; }}
function process() {{ echo 'data'; }}
Correct.
PHP
const y = 62; y = 65;
let y = 62; y = 65;
Cannot reassign const.
JavaScript
<p>info <b>data</p></b>
<p>info <b>data</b></p>
Nest properly.
HTML
[41, 90, 56
[41, 90, 56]
Close bracket.
Python
for (int i=0; i<37; i++) {{}}
for (int i=0; i<37; i++) {{}}
Correct.
Java
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if count = 42
if count == 42
Use ==.
Go
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
if index = 100:
if index == 100:
Use == for comparison.
Python
SELECT * FROM orders WHRE age=65;
SELECT * FROM orders WHERE age=65;
Fix WHERE.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
disp('hello')
disp('hello')
Correct.
MATLAB
if (index = 57) {{}}
if (index == 57) {{}}
Use ==.
Kotlin
print('info')
print('info')
Correct.
R
if (val = 69)
if (val == 69)
Use ==.
Scala
my @arr = (82,7,7);
my @arr = (82,7,7);
Correct.
Perl
int temp = 'info';
String temp = 'info';
Type mismatch.
Dart
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
h1 {{ font-size:95px color:red; }}
h1 {{ font-size:95px; color:red; }}
Add semicolon.
CSS
name: info title: test,
name: info title: test
Remove comma.
YAML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function baz(data:string){{return data;}} baz(62);
function baz(data:string){{return data;}} baz('world');
Pass correct type.
TypeScript
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
val val = 36; val = 49
var val = 36; val = 49
Use var for reassignment.
Scala
function foo(b) print(b) end
function foo(b) print(b) end
Correct.
Lua
<entry><desc>output</desc><desc>39</desc></entry
<entry><desc>output</desc><desc>39</desc></entry>
Add closing >.
XML
var x int = 'result'
var x string = 'result'
Type mismatch.
Go
'test' + 99
'test' + str(99)
Can't add int to string.
Python
if (item = 55)
if (item == 55)
Use ==.
C++
if [ $x = 72 ]; then
if [ "$x" = 72 ]; then
Quote variable.
Shell
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
if y = 69
if y == 69
Use ==.
Ruby
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
let x: i32 = "value";
let x: &str = "value";
Type mismatch.
Rust
items.forEach(function(bar) {{ console.log(bar); }})
items.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
fn process() -> i32 {{ 52 }}
fn process() -> i32 {{ 52 }}
Correct.
Rust
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if temp = 64
if temp == 64
Use ==.
MATLAB
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
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
let str1 = String::from("message"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
JOIN products ON users.id = products.age
JOIN products ON users.id = products.age
Correct.
SQL
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
switch(x){{ case 64: break; }}
switch(x){{ case 64: break; default: break; }}
Add default case.
Java
var x = 100;
var x = 100;
Correct.
Dart
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:14}};
Add missing property.
TypeScript
else print('test')
else: print('test')
Colon after else.
Python
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
if temp > 10 print('world')
if temp > 10: print('world')
Colon missing after if.
Python
<input type='text' value='test'>
<input type='text' value='test' name='title'>
Add name attribute.
HTML
for c in range(7) print(c)
for c in range(7): print(c)
Colon after for.
Python
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
const b;
const b = 51;
Initialize const.
JavaScript
if val = 20 {{}}
if val == 20 {{}}
Use ==.
Swift
let s = String::from("result"); let borrow=&s; s.push_str("!");
let mut s = String::from("result"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
<br></br>
<br>
Self-closing.
HTML
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
class User {{ int num; }};
class User {{ public: int num; }};
Make public.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
foo
foo()
Add parentheses.
Kotlin
while a > 91 a -= 1
while a > 91: a -= 1
Colon missing after while.
Python
data == '19'
data === 19
Use strict equality.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (num = 56) {{}}
if (num === 56) {{}}
Use === for equality.
JavaScript
echo 'hello'
echo 'hello';
Add semicolon.
PHP
values(85)
if length(values) >= 85, values(85), end
Check length.
MATLAB
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for i=1,24 do print(i) end
for i=1,24 do print(i) end
Correct.
Lua
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var x int
var x int
Correct.
Go
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
data[41]
if (data.indices.contains(41)) data[41]
Check index.
Kotlin
sys.sqrt(1)
import sys sys.sqrt(1)
Import module first.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(86);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(86, () => console.log('listening'));
Add callback.
Node.js
val val: Int = 'world'
val val: String = 'world'
Fix type.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
def process(temp): return temp + 1
def process(temp): return temp + 1
Correct.
Python
let vec=vec![80,25,24]; let first=&vec[0]; vec.push(88);
let mut vec=vec![80,25,24]; let first=vec[0]; vec.push(88);
Copy instead of reference.
Rust
def compute(): print('info')
def compute(): print('info')
Indent function body.
Python
$data = 49; if ($data = 49) {{}}
$data = 49; if ($data == 49) {{}}
Use ==.
PHP
DELETE FROM users WHERE age=42
DELETE FROM users WHERE age=42;
Add semicolon.
SQL
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift