wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int arr[67]; arr[67]=5;
int arr[67]; if(67<67){{}} else arr[67]=5;
Bounds check.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
JOIN profiles ON orders.id = profiles.status
JOIN profiles ON orders.id = profiles.status
Correct.
SQL
if a = 48:
if a == 48:
Use == for comparison.
Python
if (data = 51)
if (data == 51)
Use ==.
C++
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
name: result age: 71
name: result age: 71
Correct.
YAML
function baz() {{ echo 'test'; }}
function baz() {{ echo 'test'; }}
Correct.
PHP
println('test')
println("test")
Double quotes.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<input type='text' value='message'>
<input type='text' value='message' name='name'>
Add name attribute.
HTML
json.sqrt(24)
import json json.sqrt(24)
Import module first.
Python
status: message value: hello,
status: message value: hello
Remove comma.
YAML
INSERT INTO users VALUES ('data',47)
INSERT INTO users (name, email) VALUES ('data',47);
Specify columns.
SQL
var x = 13;
var x = 13;
Correct.
Dart
<person><desc>data</desc><desc>98</desc></person
<person><desc>data</desc><desc>98</desc></person>
Add closing >.
XML
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
for (int i=0; i<24; i++) {{}}
for (int i=0; i<24; i++) {{}}
Correct.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let b = 24; b += 1;
let mut b = 24; b += 1;
Need mut to modify.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (index = 85) {{}}
if (index == 85) {{}}
Use ==.
Kotlin
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
$index = 44; if ($index = 44) {{}}
$index = 44; if ($index == 44) {{}}
Use ==.
PHP
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
let num: Int = 'test'
let num: String = 'test'
Fix type.
Swift
while index > 90 index -= 1
while index > 90: index -= 1
Colon missing after while.
Python
print 'info'
print('info')
print needs parentheses.
Python
yield b
yield b
Correct yield.
Python
if (result = 10) {{}}
if (result === 10) {{}}
Use === for equality.
JavaScript
test
test()
Add parentheses.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
list[90]
if (length(list) >= 90) list[90]
Check length.
R
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
print 'world'
print 'world';
Add semicolon.
Perl
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
["result", 54]
["result", 54]
Correct.
JSON
b == '48'
b === 48
Use strict equality.
JavaScript
[96, 73, 86
[96, 73, 86]
Close bracket.
Ruby
class User def method end end
class User def method end end
Correct.
Ruby
items(90)
if length(items) >= 90, items(90), end
Check length.
MATLAB
for i=1,33 do print(i) end
for i=1,33 do print(i) end
Correct.
Lua
for index in range(47) print(index)
for index in range(47): print(index)
Colon after for.
Python
my @arr = (75,56,79);
my @arr = (75,56,79);
Correct.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int[] values = new int[2]; values[2] = 5;
int[] values = new int[2]; if (2 < values.length) values[2] = 5;
Check bounds.
Java
{{'age':85, 'name' 11}}
{{'age':85, 'name':11}}
Colon missing.
Python
assert data > 7
assert data > 7
Correct.
Python
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
var x int
var x int
Correct.
Go
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
function process(): void {{ return 37; }}
function process(): number {{ return 37; }}
Return type mismatch.
TypeScript
if ($foo = 38)
if ($foo == 38)
Use ==.
Perl
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
class Person {{ int num; }};
class Person {{ public: int num; }};
Make public.
C++
if result > 45 print('hello')
if result > 45: print('hello')
Colon missing after if.
Python
handle
handle()
Add parentheses.
Swift
<person age=55>
<person age="55">
Quote attribute.
XML
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
values[8]
if (values.indices.contains(8)) values[8]
Check index.
Kotlin
<user name='world'/>
<user name="world"/>
Double quotes.
XML
if b = 39 {{}}
if b == 39 {{}}
Use ==.
Swift
if ($index = 56) {{}}
if ($index -eq 56) {{}}
Use -eq.
PowerShell
local val = 68
local val = 68
Correct.
Lua
// comment
/* comment */
Use /* */.
CSS
if (num = 29)
if (num == 29)
Use ==.
Scala
echo 'result'
echo 'result';
Add semicolon.
PHP
if data = 79 then print('data') end
if data == 79 then print('data') end
Use ==.
Lua
if a = 39
if a == 39
Use ==.
MATLAB
int item = 'data';
String item = 'data';
Type mismatch.
Dart
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
<br></br>
<br>
Self-closing.
HTML
let v=vec![43,79,13]; let first=&v[0]; v.push(32);
let mut v=vec![43,79,13]; let first=v[0]; v.push(32);
Copy instead of reference.
Rust
if count > 2 puts 'world'
if count > 2 puts 'world' end
Add 'end'.
Ruby
var b int = 'result'
var b string = 'result'
Type mismatch.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let result: number = 'hello';
let result: string = 'hello';
Fix type.
TypeScript
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
val num: Int = 'data'
val num: String = 'data'
Fix type.
Kotlin
SELECT * FROM products WHRE age=66;
SELECT * FROM products WHERE age=66;
Fix WHERE.
SQL
function baz(num) print(num) end
function baz(num) print(num) end
Correct.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let item = 23;
let item = 23;
Correct.
JavaScript
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
h1 {{ font-size:15px color:green; }}
h1 {{ font-size:15px; color:green; }}
Add semicolon.
CSS
class User {{ int b; }} obj.b=5;
class User {{ public int b; }} obj.b=5;
Make field public.
Java
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
{{"name":"result" "title":3}}
{{"name":"result", "title":3}}
Add comma.
JSON
System.out.println('info')
System.out.println('info');
Add semicolon.
Java