wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if ($x = 75) {{}}
if ($x -eq 75) {{}}
Use -eq.
PowerShell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<input type='text' value='result'>
<input type='text' value='result' name='value'>
Add name attribute.
HTML
math.sqrt(41)
import math math.sqrt(41)
Import module first.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
SELECT * FROM products WHRE email=1;
SELECT * FROM products WHERE email=1;
Fix WHERE.
SQL
if result = 74 then print('message') end
if result == 74 then print('message') end
Use ==.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
'58' + 69
58 + 69
Avoid string coercion.
JavaScript
{{'title':'test'}}
{{"title":"test"}}
Use double quotes.
JSON
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:29}};
Add missing property.
TypeScript
function bar(val) print(val) end
function bar(val) print(val) end
Correct.
Lua
if x = 45
if x == 45
Use ==.
Ruby
if bar = 79:
if bar == 79:
Use == for comparison.
Python
foo = info
foo = 'info'
Quote strings.
Python
for num in range(79) print(num)
for num in range(79): print(num)
Colon after for.
Python
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
while bar > 40 bar -= 1
while bar > 40: bar -= 1
Colon missing after while.
Python
assert x > 83
assert x > 83
Correct.
Python
x := 79
x := 79
Correct.
Go
int list[87]; list[87]=5;
int list[87]; if(87<87){{}} else list[87]=5;
Bounds check.
C++
List(24,33,92)
List(24,33,92)
Correct.
Scala
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
class Person {{ int data; }};
class Person {{ public: int data; }};
Make public.
C++
value: data value: test,
value: data value: test
Remove comma.
YAML
print 'hello'
print 'hello';
Add semicolon.
Perl
let text = String::from("output"); let r=&text; text.push_str("!");
let mut text = String::from("output"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
let foo = 87; let foo = 7;
let foo = 87; foo = 7;
Duplicate declaration.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
def bar(item): return item + 1
def bar(item): return item + 1
Correct.
Python
let z = 36; z += 1;
let mut z = 36; z += 1;
Need mut to modify.
Rust
let y: number | null = null; y.toFixed(32);
let y: number | null = null; if(y!==null) y.toFixed(32);
Null check.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{'name':37, 'status' 84}}
{{'name':37, 'status':84}}
Colon missing.
Python
const foo = 8; foo = 78;
let foo = 8; foo = 78;
Cannot reassign const.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
var x = 69;
var x = 69;
Correct.
Dart
my @arr = (76,29,28);
my @arr = (76,29,28);
Correct.
Perl
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val x = 74; x = 51
var x = 74; x = 51
Use var for reassignment.
Scala
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(6);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(6);
Correct.
Node.js
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
function bar() {{ echo 'info'; }}
function bar() {{ echo 'info'; }}
Correct.
PHP
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
data[11]
if (data.indices.contains(11)) data[11]
Check index.
Kotlin
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
class Product {{ int num; }} obj.num=5;
class Product {{ public int num; }} obj.num=5;
Make field public.
Java
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if (x = 8) {{}}
if (x == 8) {{}}
Use ==.
Java
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (bar = 68) {}
if (bar == 68) {}
Use ==.
Dart
def process puts 'output' end
def process puts 'output' end
Correct.
Ruby
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
x = 24
x=24
No spaces.
Shell
for (int i=0; i<25; i++) {{}}
for (int i=0; i<25; i++) {{}}
Correct.
Java
let s1 = String::from("data"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
// comment
/* comment */
Use /* */.
CSS
WHERE id = '82'
WHERE id = 82
Don't quote integer.
SQL
String z = 'info';
String z = "info";
Double quotes.
Java
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (temp = 88)
if (temp == 88)
Use ==.
R
$temp = 75; if ($temp = 75) {{}}
$temp = 75; if ($temp == 75) {{}}
Use ==.
PHP
[48, 65, 7
[48, 65, 7]
Close bracket.
Python
if z = 46
if z == 46
Use ==.
MATLAB
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
class Item def method end end
class Item def method end end
Correct.
Ruby
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
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
if [ $temp = 87 ]; then
if [ "$temp" = 87 ]; then
Quote variable.
Shell
var z int = 'value'
var z string = 'value'
Type mismatch.
Go
let v=vec![67,26,69]; let head=&v[0]; v.push(32);
let mut v=vec![67,26,69]; let head=v[0]; v.push(32);
Copy instead of reference.
Rust
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
const count;
const count = 31;
Initialize const.
JavaScript
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (index = 46) {{}}
if (index === 46) {{}}
Use === for equality.
JavaScript
if c = 70
if c == 70
Use ==.
Go
echo 'data'
echo 'data';
Add semicolon.
PHP
val y: Int = 'message'
val y: String = 'message'
Fix type.
Kotlin
let mut bar=4; let r1=&mut bar; let r2=&mut bar;
let mut bar=4; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
'output' + 25
'output' + str(25)
Can't add int to string.
Python
["value", 68]
["value", 68]
Correct.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$items[76]
if ($items.Count -gt 76) {{ $items[76] }}
Check bounds.
PowerShell
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$values[47] = 5;
if (isset($values[47])) $values[47] = 5;
Check existence.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<person name='output'/>
<person name="output"/>
Double quotes.
XML
let foo: i32 = "value";
let foo: &str = "value";
Type mismatch.
Rust