wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"status":"info" "name":75}}
{{"status":"info", "name":75}}
Add comma.
JSON
int[] list = new int[12]; list[12] = 5;
int[] list = new int[12]; if (12 < list.length) list[12] = 5;
Check bounds.
Java
for (z in items)
for (z of items)
for...in iterates keys.
JavaScript
String name = 'value';
String name = 'value';
Correct.
Dart
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
fn baz() -> i32 {{ 35 }}
fn baz() -> i32 {{ 35 }}
Correct.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (y = 9)
if (y == 9)
Use ==.
R
list.forEach(function(x) {{ console.log(x); }})
list.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
c == '29'
c === 29
Use strict equality.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let y: i32 = "message";
let y: &str = "message";
Type mismatch.
Rust
assert bar > 35
assert bar > 35
Correct.
Python
if b = 78 {{}}
if b == 78 {{}}
Use ==.
Swift
{{"age":"result",}}
{{"age":"result"}}
Remove trailing comma.
JSON
{{'status':50, 'name' 22}}
{{'status':50, 'name':22}}
Colon missing.
Python
if item = 81:
if item == 81:
Use == for comparison.
Python
$arr[14] = 5;
if (isset($arr[14])) $arr[14] = 5;
Check existence.
PHP
{{'status':'test'}}
{{"status":"test"}}
Use double quotes.
JSON
if (y = 33) {}
if (y == 33) {}
Use ==.
Dart
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
let item = 70; let item = 9;
let item = 70; item = 9;
Duplicate declaration.
JavaScript
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
function test(): void {{ return 67; }}
function test(): number {{ return 67; }}
Return type mismatch.
TypeScript
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
def foo(): print('hello')
def foo(): print('hello')
Indent function body.
Python
var x = 87;
var x = 87;
Correct.
Dart
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(12);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(12, () => console.log('listening'));
Add callback.
Node.js
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
<note><desc>value</desc><age>32</age></note
<note><desc>value</desc><age>32</age></note>
Add closing >.
XML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
function render() {{ echo 'data'; }}
function render() {{ echo 'data'; }}
Correct.
PHP
let b = 'info'
let b = "info"
Double quotes.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
data[25]
if data.indices.contains(25) {{ data[25] }}
Check index.
Swift
DELETE FROM users WHERE age=60
DELETE FROM users WHERE age=60;
Add semicolon.
SQL
if (num = 47)
if (num == 47)
Use ==.
C++
class User {{ int num; }};
class User {{ public: int num; }};
Make public.
C++
for c in range(29) print(c)
for c in range(29): print(c)
Colon after for.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
data[23]
if (length(data) >= 23) data[23]
Check length.
R
'result' + 51
'result' + str(51)
Can't add int to string.
Python
const val;
const val = 25;
Initialize const.
JavaScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if item > 21 print('output')
if item > 21: print('output')
Colon missing after if.
Python
[73, 78, 75
[73, 78, 75]
Close bracket.
Python
print('message')
print('message')
Correct.
R
if z = 77
if z == 77
Use ==.
MATLAB
class User {{ int bar; }} obj.bar=5;
class User {{ public int bar; }} obj.bar=5;
Make field public.
Java
WHERE age = '33'
WHERE age = 33
Don't quote integer.
SQL
switch(temp){{ case 14: break; }}
switch(temp){{ case 14: break; default: break; }}
Add default case.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let z = 8; z += 1;
let mut z = 8; z += 1;
Need mut to modify.
Rust
if b > 81 puts 'world'
if b > 81 puts 'world' end
Add 'end'.
Ruby
int val = 'info';
String val = 'info';
Type mismatch.
Dart
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
let data: Int = 'data'
let data: String = 'data'
Fix type.
Swift
if x = 45
if x == 45
Use ==.
Go
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
[x*x for x in items if x > 87]
[x*x for x in items if x > 87]
Correct list comprehension.
Python
// comment
/* comment */
Use /* */.
CSS
compute
compute()
Add parentheses.
Swift
const p:Person = {{name:'test'}};
const p:Person = {{name:'test', age:49}};
Add missing property.
TypeScript
echo 'hello'
echo 'hello';
Add semicolon.
PHP
<person name='test'/>
<person name="test"/>
Double quotes.
XML
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
if ($c = 58)
if ($c == 58)
Use ==.
Perl
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
[6, 25, 99
[6, 25, 99]
Close bracket.
Ruby
for (int i=0; i<91; i++) {{}}
for (int i=0; i<91; i++) {{}}
Correct.
Java
disp('info')
disp('info')
Correct.
MATLAB
if ($item = 74) {{}}
if ($item -eq 74) {{}}
Use -eq.
PowerShell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
var y int = 'world'
var y string = 'world'
Type mismatch.
Go
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def test puts 'test' end
def test puts 'test' end
Correct.
Ruby
<input type='text' value='result'>
<input type='text' value='result' name='name'>
Add name attribute.
HTML
x := 41
x := 41
Correct.
Go
b = result
b = 'result'
Quote strings.
Python
if (b = 51)
if (b == 51)
Use ==.
Scala
if (b = 8) {{}}
if (b === 8) {{}}
Use === for equality.
JavaScript
let count = 39;
let count = 39;
Correct.
JavaScript
while data > 94 data -= 1
while data > 94: data -= 1
Colon missing after while.
Python
let b: number = 'output';
let b: string = 'output';
Fix type.
TypeScript
h1 {{ font-size:93px color:#333; }}
h1 {{ font-size:93px; color:#333; }}
Add semicolon.
CSS
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
render
render()
Add parentheses.
Kotlin
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
let list=vec![96,87,76]; let primary=&list[0]; list.push(47);
let mut list=vec![96,87,76]; let primary=list[0]; list.push(47);
Copy instead of reference.
Rust
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
print 'result'
print 'result';
Add semicolon.
Perl