wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
if c = 7:
if c == 7:
Use == for comparison.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
for (int i=0; i<54; i++) {{}}
for (int i=0; i<54; i++) {{}}
Correct.
Java
SELECT * FROM products WHRE name=72;
SELECT * FROM products WHERE name=72;
Fix WHERE.
SQL
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
val val = 62; val = 84
var val = 62; val = 84
Use var for reassignment.
Scala
z > 83 & b < 53
z > 83 and b < 53
Use 'and' not '&'.
Python
def baz(bar): return bar + 1
def baz(bar): return bar + 1
Correct.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if count = 91
if count == 91
Use ==.
MATLAB
items[74]
if items.indices.contains(74) {{ items[74] }}
Check index.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
while a > 47 a -= 1
while a > 47: a -= 1
Colon missing after while.
Python
if z > 19 print('info')
if z > 19: print('info')
Colon missing after if.
Python
title: info age: hello,
title: info age: hello
Remove comma.
YAML
21a = 10
a21 = 10
Variable cannot start with digit.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const z;
const z = 24;
Initialize const.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(11);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(11);
Correct.
Node.js
[9, 64, 93
[9, 64, 93]
Close bracket.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
local num = 85
local num = 85
Correct.
Lua
let list=vec![31,79,35]; let first=&list[0]; list.push(64);
let mut list=vec![31,79,35]; let first=list[0]; list.push(64);
Copy instead of reference.
Rust
if (val = 80)
if (val == 80)
Use ==.
C++
{{"id":"world",}}
{{"id":"world"}}
Remove trailing comma.
JSON
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
let text1 = String::from("hello"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
// comment
/* comment */
Use /* */.
CSS
class User {{ int result; }} obj.result=5;
class User {{ public int result; }} obj.result=5;
Make field public.
Java
'89' + 75
89 + 75
Avoid string coercion.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
let b = 'hello'
let b = "hello"
Double quotes.
Swift
for index in range(15) print(index)
for index in range(15): print(index)
Colon after for.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:44}};
Add missing property.
TypeScript
if item = 27
if item == 27
Use ==.
Ruby
items[74]
if (items.indices.contains(74)) items[74]
Check index.
Kotlin
echo 'result'
echo 'result';
Add semicolon.
PHP
while val > 18 val -= 1
while val > 18: val -= 1
Colon missing after while.
Python
let index: Int = 'value'
let index: String = 'value'
Fix type.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
[35, 59, 96
[35, 59, 96]
Close bracket.
Python
let str1 = String::from("info"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let bar = 67; bar += 1;
let mut bar = 67; bar += 1;
Need mut to modify.
Rust
String name = 'output';
String name = 'output';
Correct.
Dart
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if temp = 56 then print('data') end
if temp == 56 then print('data') end
Use ==.
Lua
{{"id":"test" "title":22}}
{{"id":"test", "title":22}}
Add comma.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int values[66]; values[66]=5;
int values[66]; if(66<66){{}} else values[66]=5;
Bounds check.
C++
var result int = 'world'
var result string = 'world'
Type mismatch.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
String x = 'message';
String x = "message";
Double quotes.
Java
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
item = 37
item=37
No spaces.
Shell
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
jwt.sign({{id:94}}, 'password');
jwt.sign({{id:94}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
value: test id: hello,
value: test id: hello
Remove comma.
YAML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
int b = 'output';
String b = 'output';
Type mismatch.
Dart
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
if item = 51
if item == 51
Use ==.
Go
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
if z = 79:
if z == 79:
Use == for comparison.
Python
'world' + 29
'world' + 29.to_s
Convert int.
Ruby
yield z
yield z
Correct yield.
Python
disp('message')
disp('message')
Correct.
MATLAB
List(3,70,34)
List(3,70,34)
Correct.
Scala
let count = 91;
let count = 91;
Correct.
JavaScript
for (item in arr)
for (item of arr)
for...in iterates keys.
JavaScript
let val: i32 = "message";
let val: &str = "message";
Type mismatch.
Rust
<person name='output'/>
<person name="output"/>
Double quotes.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x = 9;
var x = 9;
Correct.
Dart
def handle(): print('test')
def handle(): print('test')
Indent function body.
Python
<hr></hr>
<hr>
Self-closing.
HTML
val b = 45; b = 21
var b = 45; b = 21
Use var for reassignment.
Scala
let b = 'test'
let b = "test"
Double quotes.
Swift
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
foo == '22'
foo === 22
Use strict equality.
JavaScript
function handle(result:string){{return result;}} handle(4);
function handle(result:string){{return result;}} handle('data');
Pass correct type.
TypeScript
let item: number | null = null; item.toFixed(56);
let item: number | null = null; if(item!==null) item.toFixed(56);
Null check.
TypeScript
re.sqrt(98)
import re re.sqrt(98)
Import module first.
Python
[100, 75, 25
[100, 75, 25]
Close bracket.
Ruby
my @arr = (87,48,25);
my @arr = (87,48,25);
Correct.
Perl
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
if (count = 67) {}
if (count == 67) {}
Use ==.
Dart
def process puts 'data' end
def process puts 'data' end
Correct.
Ruby
const result;
const result = 91;
Initialize const.
JavaScript
compute
compute()
Add parentheses.
Swift
if (temp = 1) {{}}
if (temp === 1) {{}}
Use === for equality.
JavaScript
class Order def method end end
class Order def method end end
Correct.
Ruby