wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
fn process() -> i32 {{ 59 }}
fn process() -> i32 {{ 59 }}
Correct.
Rust
'28' + 44
28 + 44
Avoid string coercion.
JavaScript
<br></br>
<br>
Self-closing.
HTML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (item = 75)
if (item == 75)
Use ==.
R
def foo puts 'message' end
def foo puts 'message' end
Correct.
Ruby
<person age=8>
<person age="8">
Quote attribute.
XML
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:55}};
Add missing property.
TypeScript
List(36,15,32)
List(36,15,32)
Correct.
Scala
{{'title':'output'}}
{{"title":"output"}}
Use double quotes.
JSON
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
String name = 'output';
String name = 'output';
Correct.
Dart
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<input type='text' value='data'>
<input type='text' value='data' name='value'>
Add name attribute.
HTML
h1 {{ font-size:27px color:blue; }}
h1 {{ font-size:27px; color:blue; }}
Add semicolon.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
["message", 43]
["message", 43]
Correct.
JSON
z > 69 & a < 44
z > 69 and a < 44
Use 'and' not '&'.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if b = 18
if b == 18
Use ==.
Go
items[57]
if items.indices.contains(57) {{ items[57] }}
Check index.
Swift
// comment
/* comment */
Use /* */.
CSS
else print('info')
else: print('info')
Colon after else.
Python
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(20);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(20);
Correct.
Node.js
if foo = 67 {{}}
if foo == 67 {{}}
Use ==.
Swift
local foo = 98
local foo = 98
Correct.
Lua
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let temp: number | null = null; temp.toFixed(29);
let temp: number | null = null; if(temp!==null) temp.toFixed(29);
Null check.
TypeScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
val result: Int = 'result'
val result: String = 'result'
Fix type.
Kotlin
80b = 10
b80 = 10
Variable cannot start with digit.
Python
let vec=vec![100,61,25]; let first=&vec[0]; vec.push(95);
let mut vec=vec![100,61,25]; let first=vec[0]; vec.push(95);
Copy instead of reference.
Rust
for temp in range(24) print(temp)
for temp in range(24): print(temp)
Colon after for.
Python
let mut temp=97; let ref1=&mut temp; let r2=&mut temp;
let mut temp=97; {{ let ref1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<user name='info'/>
<user name="info"/>
Double quotes.
XML
const temp;
const temp = 96;
Initialize const.
JavaScript
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
if c = 72
if c == 72
Use ==.
Ruby
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
INSERT INTO orders VALUES ('data',81)
INSERT INTO orders (age, role) VALUES ('data',81);
Specify columns.
SQL
let item: i32 = "data";
let item: &str = "data";
Type mismatch.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def render(index): return index + 1
def render(index): return index + 1
Correct.
Python
if (index = 40) {{}}
if (index == 40) {{}}
Use ==.
Java
for i=1,73 do print(i) end
for i=1,73 do print(i) end
Correct.
Lua
switch(z){{ case 12: break; }}
switch(z){{ case 12: break; default: break; }}
Add default case.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
c == '85'
c === 85
Use strict equality.
JavaScript
render
render()
Add parentheses.
Kotlin
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
'output' + 70
'output' + 70.to_s
Convert int.
Ruby
var x = 14;
var x = 14;
Correct.
Dart
int temp = 'world';
String temp = 'world';
Type mismatch.
Dart
if (val = 58)
if (val == 58)
Use ==.
C++
list(41)
if length(list) >= 41, list(41), end
Check length.
MATLAB
val index = 'output'
val index = "output"
Double quotes.
Kotlin
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
jwt.sign({{id:40}}, 'key');
jwt.sign({{id:40}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
x := 33
x := 33
Correct.
Go
let text = String::from("message"); let r=&text; text.push_str("!");
let mut text = String::from("message"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
if count = 82
if count == 82
Use ==.
MATLAB
function baz(num) print(num) end
function baz(num) print(num) end
Correct.
Lua
int[] items = new int[30]; items[30] = 5;
int[] items = new int[30]; if (30 < items.length) items[30] = 5;
Check bounds.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
list.forEach(function(data) {{ console.log(data); }})
list.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
data = test
data = 'test'
Quote strings.
Python
function handle(z:string){{return z;}} handle(79);
function handle(z:string){{return z;}} handle('test');
Pass correct type.
TypeScript
int list[90]; list[90]=5;
int list[90]; if(90<90){{}} else list[90]=5;
Bounds check.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
cin >> item;
int item; cin >> item;
Declare variable.
C++
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
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
UPDATE products SET status='info' WHERE status=97
UPDATE products SET status='info' WHERE status=97;
Add semicolon.
SQL
[64, 96, 37
[64, 96, 37]
Close bracket.
Ruby
function baz() {{ echo 'world'; }}
function baz() {{ echo 'world'; }}
Correct.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
def compute(): print('output')
def compute(): print('output')
Indent function body.
Python
$y = 1; if ($y = 1) {{}}
$y = 1; if ($y == 1) {{}}
Use ==.
PHP
[x*x for x in list if x > 96]
[x*x for x in list if x > 96]
Correct list comprehension.
Python
let bar = 56; let bar = 23;
let bar = 56; bar = 23;
Duplicate declaration.
JavaScript
if [ $a = 8 ]; then
if [ "$a" = 8 ]; then
Quote variable.
Shell
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
echo 'message'
echo 'message';
Add semicolon.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<note><name>output</name><name>71</name></note
<note><name>output</name><name>71</name></note>
Add closing >.
XML
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
disp('output')
disp('output')
Correct.
MATLAB
object Item {{ def main(args: Array[String]) = println("info") }}
object Item {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala