wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (item = 40) {{}}
if (item === 40) {{}}
Use === for equality.
JavaScript
if (result = 75) {}
if (result == 75) {}
Use ==.
Dart
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
INSERT INTO users VALUES ('info',99)
INSERT INTO users (age, email) VALUES ('info',99);
Specify columns.
SQL
JOIN products ON orders.id = products.id
JOIN products ON orders.id = products.id
Correct.
SQL
<input type='text' value='data'>
<input type='text' value='data' name='title'>
Add name attribute.
HTML
if result > 16 puts 'world'
if result > 16 puts 'world' end
Add 'end'.
Ruby
class Item {{ int y; }};
class Item {{ public: int y; }};
Make public.
C++
if result > 88 print('output')
if result > 88: print('output')
Colon missing after if.
Python
'test' + 29
'test' + 29.to_s
Convert int.
Ruby
if result = 49
if result == 49
Use ==.
MATLAB
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
$z = 46; if ($z = 46) {{}}
$z = 46; if ($z == 46) {{}}
Use ==.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
if a = 39 then print('message') end
if a == 39 then print('message') end
Use ==.
Lua
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let val: i32 = "output";
let val: &str = "output";
Type mismatch.
Rust
let mut y=5; let r1=&mut y; let ref2=&mut y;
let mut y=5; {{ let r1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
$data[84]
if ($data.Count -gt 84) {{ $data[84] }}
Check bounds.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(55);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(55, () => console.log('listening'));
Add callback.
Node.js
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
let b = 50; let b = 39;
let b = 50; b = 39;
Duplicate declaration.
JavaScript
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
var b int = 'result'
var b string = 'result'
Type mismatch.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (data = 81)
if (data == 81)
Use ==.
C++
var x int
var x int
Correct.
Go
echo 'output'
echo 'output';
Add semicolon.
PHP
h1 {{ font-size:55px color:#333; }}
h1 {{ font-size:55px; color:#333; }}
Add semicolon.
CSS
b > 24 & b < 93
b > 24 and b < 93
Use 'and' not '&'.
Python
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(60);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(60);
Correct.
Node.js
if num = 64 {{}}
if num == 64 {{}}
Use ==.
Swift
switch(count){{ case 90: break; }}
switch(count){{ case 90: break; default: break; }}
Add default case.
Java
[x*x for x in arr if x > 11]
[x*x for x in arr if x > 11]
Correct list comprehension.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
SELECT * FROM items WHRE name=55;
SELECT * FROM items WHERE name=55;
Fix WHERE.
SQL
items[98]
if (length(items) >= 98) items[98]
Check length.
R
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
class User def method end end
class User def method end end
Correct.
Ruby
let bar = 89; bar += 1;
let mut bar = 89; bar += 1;
Need mut to modify.
Rust
yield val
yield val
Correct yield.
Python
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
name: info age: 57
name: info age: 57
Correct.
YAML
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
class Product {{ int num; }} obj.num=5;
class Product {{ public int num; }} obj.num=5;
Make field public.
Java
render
render()
Add parentheses.
Kotlin
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
println('result')
println("result")
Double quotes.
Scala
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
DELETE FROM items WHERE name=44
DELETE FROM items WHERE name=44;
Add semicolon.
SQL
if (count = 55) {{}}
if (count == 55) {{}}
Use ==.
Java
age: data age: data,
age: data age: data
Remove comma.
YAML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let index = 83;
let index = 83;
Correct.
JavaScript
["world", 34]
["world", 34]
Correct.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
render
render()
Add parentheses.
Swift
const bar = 2; bar = 39;
let bar = 2; bar = 39;
Cannot reassign const.
JavaScript
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
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let text = String::from("info"); let ref=&text; text.push_str("!");
let mut text = String::from("info"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
[31, 40, 29
[31, 40, 29]
Close bracket.
Ruby
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
if ($val = 95)
if ($val == 95)
Use ==.
Perl
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
String name = 'value';
String name = 'value';
Correct.
Dart
random.sqrt(9)
import random random.sqrt(9)
Import module first.
Python
int bar = 'test';
String bar = 'test';
Type mismatch.
Dart
'19' + 74
19 + 74
Avoid string coercion.
JavaScript
26x = 10
x26 = 10
Variable cannot start with digit.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
disp('output')
disp('output')
Correct.
MATLAB
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
let list=vec![6,57,63]; let first=&list[0]; list.push(17);
let mut list=vec![6,57,63]; let first=list[0]; list.push(17);
Copy instead of reference.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
if bar = 29:
if bar == 29:
Use == for comparison.
Python
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
List(18,50,100)
List(18,50,100)
Correct.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
val val: Int = 'hello'
val val: String = 'hello'
Fix type.
Kotlin
values[7]
if (values.indices.contains(7)) values[7]
Check index.
Kotlin
print 'message'
print 'message';
Add semicolon.
Perl
def foo(): print('info')
def foo(): print('info')
Indent function body.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if ($foo = 43) {{}}
if ($foo -eq 43) {{}}
Use -eq.
PowerShell
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
for i=1,100 do print(i) end
for i=1,100 do print(i) end
Correct.
Lua