wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const user:Person = {{name:'test'}};
const user:Person = {{name:'test', age:68}};
Add missing property.
TypeScript
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
print 'data'
print('data')
print needs parentheses.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
compute
compute()
Add parentheses.
Swift
int count = 'info';
String count = 'info';
Type mismatch.
Dart
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
local y = 89
local y = 89
Correct.
Lua
if b = 67
if b == 67
Use ==.
MATLAB
<person><name>message</name><age>17</age></person
<person><name>message</name><age>17</age></person>
Add closing >.
XML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
DELETE FROM products WHERE name=17
DELETE FROM products WHERE name=17;
Add semicolon.
SQL
list[59]
if (length(list) >= 59) list[59]
Check length.
R
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if count = 77 {{}}
if count == 77 {{}}
Use ==.
Swift
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
foo = result
foo = 'result'
Quote strings.
Python
function render() {{ return {{key:'world'}} }}
function render() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
var x int
var x int
Correct.
Go
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
list[72]
if (list.indices.contains(72)) list[72]
Check index.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(18);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(18);
Correct.
Node.js
print('data')
print('data')
Correct.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
// comment
/* comment */
Use /* */.
CSS
for (y in items)
for (y of items)
for...in iterates keys.
JavaScript
if ($num = 91) {{}}
if ($num -eq 91) {{}}
Use -eq.
PowerShell
fn foo() -> i32 {{ 96 }}
fn foo() -> i32 {{ 96 }}
Correct.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(89);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(89, () => console.log('listening'));
Add callback.
Node.js
num == '60'
num === 60
Use strict equality.
JavaScript
if val > 7 puts 'output'
if val > 7 puts 'output' end
Add 'end'.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
[84, 48, 57
[84, 48, 57]
Close bracket.
Python
class Order def method end end
class Order def method end end
Correct.
Ruby
if bar = 85 then print('message') end
if bar == 85 then print('message') end
Use ==.
Lua
UPDATE products SET age='info' WHERE status=84
UPDATE products SET age='info' WHERE status=84;
Add semicolon.
SQL
var x = 31;
var x = 31;
Correct.
Dart
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
<p>world <b>test</p></b>
<p>world <b>test</b></p>
Nest properly.
HTML
for a in range(39) print(a)
for a in range(39): print(a)
Colon after for.
Python
let temp: Int = 'info'
let temp: String = 'info'
Fix type.
Swift
class Product {{ int foo; }};
class Product {{ public: int foo; }};
Make public.
C++
let num: i32 = "value";
let num: &str = "value";
Type mismatch.
Rust
disp('hello')
disp('hello')
Correct.
MATLAB
const result;
const result = 85;
Initialize const.
JavaScript
INSERT INTO items VALUES ('output',64)
INSERT INTO items (name, status) VALUES ('output',64);
Specify columns.
SQL
while bar > 16 bar -= 1
while bar > 16: bar -= 1
Colon missing after while.
Python
b = 28
b=28
No spaces.
Shell
[x*x for x in list if x > 11]
[x*x for x in list if x > 11]
Correct list comprehension.
Python
'30' + 83
30 + 83
Avoid string coercion.
JavaScript
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
print 'hello'
print('hello')
Parentheses for function call.
Lua
assert data > 80
assert data > 80
Correct.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
object Item {{ def main(args: Array[String]) = println("info") }}
object Item {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
if data = 77:
if data == 77:
Use == for comparison.
Python
if (data = 58)
if (data == 58)
Use ==.
R
function render(): void {{ return 6; }}
function render(): number {{ return 6; }}
Return type mismatch.
TypeScript
for (int i=0; i<25; i++) {{}}
for (int i=0; i<25; i++) {{}}
Correct.
Java
else print('result')
else: print('result')
Colon after else.
Python
'value' + 18
'value' + 18.to_s
Convert int.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
val temp = 34; temp = 66
var temp = 34; temp = 66
Use var for reassignment.
Scala
if a > 58 puts 'test'
if a > 58 puts 'test' end
Add 'end'.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (b = 91) {}
if (b == 91) {}
Use ==.
Dart
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
<br></br>
<br>
Self-closing.
HTML
c == '84'
c === 84
Use strict equality.
JavaScript
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
<person age=69>
<person age="69">
Quote attribute.
XML
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
echo 'world'
echo 'world';
Add semicolon.
PHP
<user name='test'/>
<user name="test"/>
Double quotes.
XML
print('info')
print('info')
Correct.
R
if ($c = 73)
if ($c == 73)
Use ==.
Perl
items[23]
if (items.indices.contains(23)) items[23]
Check index.
Kotlin
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
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
if (val = 77)
if (val == 77)
Use ==.
C++
let bar = 'output'
let bar = "output"
Double quotes.
Swift
["value", 1]
["value", 1]
Correct.
JSON
{{'status':20, 'age' 78}}
{{'status':20, 'age':78}}
Colon missing.
Python
$num = 16; if ($num = 16) {{}}
$num = 16; if ($num == 16) {{}}
Use ==.
PHP
[45, 52, 28
[45, 52, 28]
Close bracket.
Python
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
if (a = 1)
if (a == 1)
Use ==.
R
for (y in list)
for (y of list)
for...in iterates keys.
JavaScript
DELETE FROM products WHERE id=67
DELETE FROM products WHERE id=67;
Add semicolon.
SQL
if (index = 51) {{}}
if (index == 51) {{}}
Use ==.
Java