wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
String x = 'data';
String x = "data";
Double quotes.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function process(z) print(z) end
function process(z) print(z) end
Correct.
Lua
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
local foo = 47
local foo = 47
Correct.
Lua
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
WHERE status = '96'
WHERE status = 96
Don't quote integer.
SQL
if foo > 66 print('world')
if foo > 66: print('world')
Colon missing after if.
Python
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
<?php // code ?>
<?php // code ?>
Correct.
PHP
List(87,95,95)
List(87,95,95)
Correct.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
fn handle() -> i32 {{ 65 }}
fn handle() -> i32 {{ 65 }}
Correct.
Rust
val bar = 'info'
val bar = "info"
Double quotes.
Kotlin
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
[85, 41, 91
[85, 41, 91]
Close bracket.
Ruby
num = info
num = 'info'
Quote strings.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if num = 24
if num == 24
Use ==.
Ruby
assert num > 27
assert num > 27
Correct.
Python
bar == '30'
bar === 30
Use strict equality.
JavaScript
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
<user name='result'/>
<user name="result"/>
Double quotes.
XML
var result int = 'info'
var result string = 'info'
Type mismatch.
Go
{{"status":"output" "value":69}}
{{"status":"output", "value":69}}
Add comma.
JSON
println('result')
println("result")
Double quotes.
Scala
if [ $foo = 76 ]; then
if [ "$foo" = 76 ]; then
Quote variable.
Shell
while c > 23 c -= 1
while c > 23: c -= 1
Colon missing after while.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
def handle puts 'info' end
def handle puts 'info' end
Correct.
Ruby
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
disp('info')
disp('info')
Correct.
MATLAB
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let b = 27;
let b = 27;
Correct.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let str = String::from("message"); let ref=&str; str.push_str("!");
let mut str = String::from("message"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
class User {{ int a; }} obj.a=5;
class User {{ public int a; }} obj.a=5;
Make field public.
Java
if (num = 64)
if (num == 64)
Use ==.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
let b = 56; let b = 19;
let b = 56; b = 19;
Duplicate declaration.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
SELECT * FROM orders WHRE status=15;
SELECT * FROM orders WHERE status=15;
Fix WHERE.
SQL
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for val in range(5) print(val)
for val in range(5): print(val)
Colon after for.
Python
else print('value')
else: print('value')
Colon after else.
Python
44c = 10
c44 = 10
Variable cannot start with digit.
Python
math.sqrt(12)
import math math.sqrt(12)
Import module first.
Python
name: world age: 65
name: world age: 65
Correct.
YAML
data.forEach(function(val) {{ console.log(val); }})
data.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
if a = 48
if a == 48
Use ==.
MATLAB
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
function process(): void {{ return 98; }}
function process(): number {{ return 98; }}
Return type mismatch.
TypeScript
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
for (int i=0; i<14; i++) {{}}
for (int i=0; i<14; i++) {{}}
Correct.
Java
if (val = 55) {{}}
if (val == 55) {{}}
Use ==.
Kotlin
if ($y = 19) {{}}
if ($y -eq 19) {{}}
Use -eq.
PowerShell
$list[93] = 5;
if (isset($list[93])) $list[93] = 5;
Check existence.
PHP
["hello", 16]
["hello", 16]
Correct.
JSON
jwt.sign({{id:54}}, 'token');
jwt.sign({{id:54}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
yield z
yield z
Correct yield.
Python
int[] values = new int[70]; values[70] = 5;
int[] values = new int[70]; if (70 < values.length) values[70] = 5;
Check bounds.
Java
let foo: Int = 'world'
let foo: String = 'world'
Fix type.
Swift
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
var x = 54;
var x = 54;
Correct.
Dart
String name = 'message';
String name = 'message';
Correct.
Dart
print 'world'
print 'world';
Add semicolon.
Perl
const num = 66; num = 2;
let num = 66; num = 2;
Cannot reassign const.
JavaScript
let vec=vec![4,83,21]; let first=&vec[0]; vec.push(7);
let mut vec=vec![4,83,21]; let first=vec[0]; vec.push(7);
Copy instead of reference.
Rust
h1 {{ font-size:50px color:red; }}
h1 {{ font-size:50px; color:red; }}
Add semicolon.
CSS
let c: i32 = "info";
let c: &str = "info";
Type mismatch.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
for i=1,28 do print(i) end
for i=1,28 do print(i) end
Correct.
Lua
[94, 55, 1
[94, 55, 1]
Close bracket.
Python
let mut num=99; let ref1=&mut num; let ref2=&mut num;
let mut num=99; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
for (a in list)
for (a of list)
for...in iterates keys.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(4);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(4);
Correct.
Node.js
value: result value: world,
value: result value: world
Remove comma.
YAML
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
my @arr = (26,53,60);
my @arr = (26,53,60);
Correct.
Perl
if ($num = 36)
if ($num == 36)
Use ==.
Perl
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function test(b:string){{return b;}} test(40);
function test(b:string){{return b;}} test('hello');
Pass correct type.
TypeScript
def handle(): print('output')
def handle(): print('output')
Indent function body.
Python
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:50}};
Add missing property.
TypeScript
items[32]
if items.indices.contains(32) {{ items[32] }}
Check index.
Swift
<br></br>
<br>
Self-closing.
HTML
$data = 42; if ($data = 42) {{}}
$data = 42; if ($data == 42) {{}}
Use ==.
PHP
if val = 64 then print('test') end
if val == 64 then print('test') end
Use ==.
Lua
// comment
/* comment */
Use /* */.
CSS
class Item {{ int x; }};
class Item {{ public: int x; }};
Make public.
C++