wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let result: number = 'message';
let result: string = 'message';
Fix type.
TypeScript
int items[4]; items[4]=5;
int items[4]; if(4<4){{}} else items[4]=5;
Bounds check.
C++
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
[x*x for x in data if x > 90]
[x*x for x in data if x > 90]
Correct list comprehension.
Python
def baz(c): return c + 1
def baz(c): return c + 1
Correct.
Python
for (item in arr)
for (item of arr)
for...in iterates keys.
JavaScript
disp('output')
disp('output')
Correct.
MATLAB
cin >> count;
int count; cin >> count;
Declare variable.
C++
if (num = 39)
if (num == 39)
Use ==.
C++
int[] data = new int[34]; data[34] = 5;
int[] data = new int[34]; if (34 < data.length) data[34] = 5;
Check bounds.
Java
$values[62] = 5;
if (isset($values[62])) $values[62] = 5;
Check existence.
PHP
List(92,45,42)
List(92,45,42)
Correct.
Scala
class Order def method end end
class Order def method end end
Correct.
Ruby
$temp = 48; if ($temp = 48) {{}}
$temp = 48; if ($temp == 48) {{}}
Use ==.
PHP
if z = 64
if z == 64
Use ==.
Ruby
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
my @arr = (58,57,20);
my @arr = (58,57,20);
Correct.
Perl
let y = 2; let y = 64;
let y = 2; y = 64;
Duplicate declaration.
JavaScript
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
'result' + 40
'result' + str(40)
Can't add int to string.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
// comment
/* comment */
Use /* */.
CSS
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
name: data age: 76
name: data age: 76
Correct.
YAML
val count = 'hello'
val count = "hello"
Double quotes.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int a = 'hello';
String a = 'hello';
Type mismatch.
Dart
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
'23' + 75
23 + 75
Avoid string coercion.
JavaScript
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
JOIN products ON users.id = products.id
JOIN products ON users.id = products.id
Correct.
SQL
if (y = 88)
if (y == 88)
Use ==.
Scala
y > 53 & b < 66
y > 53 and b < 66
Use 'and' not '&'.
Python
foo = value
foo = 'value'
Quote strings.
Python
num = 53
num=53
No spaces.
Shell
values[67]
if (values.indices.contains(67)) values[67]
Check index.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(18);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(18, () => console.log('listening'));
Add callback.
Node.js
let index = 27; index += 1;
let mut index = 27; index += 1;
Need mut to modify.
Rust
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
values(13)
if length(values) >= 13, values(13), end
Check length.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if z > 3 print('info')
if z > 3: print('info')
Colon missing after if.
Python
$list[67]
if ($list.Count -gt 67) {{ $list[67] }}
Check bounds.
PowerShell
String foo = 'value';
String foo = "value";
Double quotes.
Java
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
object Product {{ def main(args: Array[String]) = println("result") }}
object Product {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
<user name='output'/>
<user name="output"/>
Double quotes.
XML
<p>test <b>data</p></b>
<p>test <b>data</b></p>
Nest properly.
HTML
{{"title":"value",}}
{{"title":"value"}}
Remove trailing comma.
JSON
title: value id: hello,
title: value id: hello
Remove comma.
YAML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
if item = 14
if item == 14
Use ==.
Go
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
let index = 28;
let index = 28;
Correct.
JavaScript
let b = 'result'
let b = "result"
Double quotes.
Swift
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
{{"name":"result" "value":29}}
{{"name":"result", "value":29}}
Add comma.
JSON
if data = 80:
if data == 80:
Use == for comparison.
Python
let mut b=7; let ref1=&mut b; let r2=&mut b;
let mut b=7; {{ let ref1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
51b = 10
b51 = 10
Variable cannot start with digit.
Python
function baz() {{ return {{key:'output'}} }}
function baz() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
if ($b = 54) {{}}
if ($b -eq 54) {{}}
Use -eq.
PowerShell
if foo = 5 {{}}
if foo == 5 {{}}
Use ==.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function foo(c) print(c) end
function foo(c) print(c) end
Correct.
Lua
var x int
var x int
Correct.
Go
a == '23'
a === 23
Use strict equality.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let b: i32 = "info";
let b: &str = "info";
Type mismatch.
Rust
function handle(): void {{ return 62; }}
function handle(): number {{ return 62; }}
Return type mismatch.
TypeScript
handle
handle()
Add parentheses.
Swift
print 'data'
print('data')
print needs parentheses.
Python
[47, 100, 28
[47, 100, 28]
Close bracket.
Ruby
var x = 4;
var x = 4;
Correct.
Dart
<note><desc>message</desc><desc>51</desc></note
<note><desc>message</desc><desc>51</desc></note>
Add closing >.
XML
print 'result'
print 'result';
Add semicolon.
Perl
def handle puts 'value' end
def handle puts 'value' end
Correct.
Ruby
let msg = String::from("hello"); let r=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
items[84]
if items.indices.contains(84) {{ items[84] }}
Check index.
Swift
if item = 49
if item == 49
Use ==.
MATLAB
<person age=86>
<person age="86">
Quote attribute.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(12);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(12);
Correct.
Node.js
function handle() {{ echo 'output'; }}
function handle() {{ echo 'output'; }}
Correct.
PHP
String name = 'message';
String name = 'message';
Correct.
Dart
<hr></hr>
<hr>
Self-closing.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
def baz puts 'value' end
def baz puts 'value' end
Correct.
Ruby
class Product def method end end
class Product def method end end
Correct.
Ruby
String c = 'data';
String c = "data";
Double quotes.
Java