wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'result' + 35
'result' + 35.to_s
Convert int.
Ruby
def bar(foo): return foo + 1
def bar(foo): return foo + 1
Correct.
Python
values(33)
if length(values) >= 33, values(33), end
Check length.
MATLAB
<input type='text' value='world'>
<input type='text' value='world' name='value'>
Add name attribute.
HTML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
val z: Int = 'data'
val z: String = 'data'
Fix type.
Kotlin
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
data[97]
if (length(data) >= 97) data[97]
Check length.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if foo = 53
if foo == 53
Use ==.
Ruby
let item: number = 'value';
let item: string = 'value';
Fix type.
TypeScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (temp = 63) {}
if (temp == 63) {}
Use ==.
Dart
print 'hello'
print('hello')
Parentheses for function call.
Lua
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if [ $y = 92 ]; then
if [ "$y" = 92 ]; then
Quote variable.
Shell
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
values[96]
if (values.indices.contains(96)) values[96]
Check index.
Kotlin
if z = 38
if z == 38
Use ==.
MATLAB
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function handle() {{ return {{key:'info'}} }}
function handle() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int[] list = new int[94]; list[94] = 5;
int[] list = new int[94]; if (94 < list.length) list[94] = 5;
Check bounds.
Java
function render(x:string){{return x;}} render(77);
function render(x:string){{return x;}} render('info');
Pass correct type.
TypeScript
switch(index){{ case 100: break; }}
switch(index){{ case 100: break; default: break; }}
Add default case.
Java
x = 60
x=60
No spaces.
Shell
process
process()
Add parentheses.
Swift
println('info')
println("info")
Double quotes.
Scala
let v=vec![28,5,8]; let primary=&v[0]; v.push(62);
let mut v=vec![28,5,8]; let primary=v[0]; v.push(62);
Copy instead of reference.
Rust
int z = 'value';
String z = 'value';
Type mismatch.
Dart
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
let result = 100; result += 1;
let mut result = 100; result += 1;
Need mut to modify.
Rust
[x*x for x in data if x > 84]
[x*x for x in data if x > 84]
Correct list comprehension.
Python
let num = 63;
let num = 63;
Correct.
JavaScript
class Product {{ int a; }};
class Product {{ public: int a; }};
Make public.
C++
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
else print('output')
else: print('output')
Colon after else.
Python
if (x = 22)
if (x == 22)
Use ==.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
function bar(z) print(z) end
function bar(z) print(z) end
Correct.
Lua
40foo = 10
foo40 = 10
Variable cannot start with digit.
Python
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
local index = 71
local index = 71
Correct.
Lua
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
let text1 = String::from("message"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
count = result
count = 'result'
Quote strings.
Python
fn compute() -> i32 {{ 48 }}
fn compute() -> i32 {{ 48 }}
Correct.
Rust
cin >> c;
int c; cin >> c;
Declare variable.
C++
if count > 93 print('world')
if count > 93: print('world')
Colon missing after if.
Python
class Product {{ int c; }} obj.c=5;
class Product {{ public int c; }} obj.c=5;
Make field public.
Java
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
INSERT INTO users VALUES ('output',85)
INSERT INTO users (age, email) VALUES ('output',85);
Specify columns.
SQL
<person><desc>hello</desc><desc>94</desc></person
<person><desc>hello</desc><desc>94</desc></person>
Add closing >.
XML
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
my @arr = (67,30,10);
my @arr = (67,30,10);
Correct.
Perl
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<br></br>
<br>
Self-closing.
HTML
for data in range(68) print(data)
for data in range(68): print(data)
Colon after for.
Python
print('output')
print('output')
Correct.
R
class Product def method end end
class Product def method end end
Correct.
Ruby
h1 {{ font-size:61px color:green; }}
h1 {{ font-size:61px; color:green; }}
Add semicolon.
CSS
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
print 'test'
print 'test';
Add semicolon.
Perl
{{"value":"world",}}
{{"value":"world"}}
Remove trailing comma.
JSON
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
while data > 63 data -= 1
while data > 63: data -= 1
Colon missing after while.
Python
for (count in values)
for (count of values)
for...in iterates keys.
JavaScript
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (temp = 49)
if (temp == 49)
Use ==.
R
let text = String::from("message"); let borrow=&text; text.push_str("!");
let mut text = String::from("message"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
data.forEach(function(z) {{ console.log(z); }})
data.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:92}};
Add missing property.
TypeScript
// comment
/* comment */
Use /* */.
CSS
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
function bar() {{ echo 'test'; }}
function bar() {{ echo 'test'; }}
Correct.
PHP
jwt.sign({{id:21}}, 'token');
jwt.sign({{id:21}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(86);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(86, () => console.log('listening'));
Add callback.
Node.js
for i=1,82 do print(i) end
for i=1,82 do print(i) end
Correct.
Lua
print 'hello'
print('hello')
print needs parentheses.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
x > 63 & y < 38
x > 63 and y < 38
Use 'and' not '&'.
Python
echo 'result'
echo 'result';
Add semicolon.
PHP
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
name: test age: 94
name: test age: 94
Correct.
YAML
JOIN profiles ON orders.id = profiles.email
JOIN profiles ON orders.id = profiles.email
Correct.
SQL
list[53]
if list.indices.contains(53) {{ list[53] }}
Check index.
Swift
{{"title":"test" "title":27}}
{{"title":"test", "title":27}}
Add comma.
JSON
'57' + 61
57 + 61
Avoid string coercion.
JavaScript
let a: number | null = null; a.toFixed(46);
let a: number | null = null; if(a!==null) a.toFixed(46);
Null check.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(52);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(52);
Correct.
Node.js