wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const y;
const y = 93;
Initialize const.
JavaScript
let x: i32 = "test";
let x: &str = "test";
Type mismatch.
Rust
def process puts 'world' end
def process puts 'world' end
Correct.
Ruby
val c: Int = 'test'
val c: String = 'test'
Fix type.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (result = 60) {{}}
if (result == 60) {{}}
Use ==.
Kotlin
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
def handle puts 'test' end
def handle puts 'test' end
Correct.
Ruby
int values[90]; values[90]=5;
int values[90]; if(90<90){{}} else values[90]=5;
Bounds check.
C++
disp('test')
disp('test')
Correct.
MATLAB
if z = 13:
if z == 13:
Use == for comparison.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
66data = 10
data66 = 10
Variable cannot start with digit.
Python
<person age=65>
<person age="65">
Quote attribute.
XML
const index;
const index = 48;
Initialize const.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(61);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(61);
Correct.
Node.js
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
<br></br>
<br>
Self-closing.
HTML
let temp = 43; temp += 1;
let mut temp = 43; temp += 1;
Need mut to modify.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(11);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(11, () => console.log('listening'));
Add callback.
Node.js
switch(num){{ case 49: break; }}
switch(num){{ case 49: break; default: break; }}
Add default case.
Java
String name = 'world';
String name = 'world';
Correct.
Dart
list(35)
if length(list) >= 35, list(35), end
Check length.
MATLAB
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
let list=vec![23,11,73]; let first=&list[0]; list.push(15);
let mut list=vec![23,11,73]; let first=list[0]; list.push(15);
Copy instead of reference.
Rust
if x = 58
if x == 58
Use ==.
MATLAB
DELETE FROM orders WHERE name=21
DELETE FROM orders WHERE name=21;
Add semicolon.
SQL
let count: Int = 'output'
let count: String = 'output'
Fix type.
Swift
$items[79]
if ($items.Count -gt 79) {{ $items[79] }}
Check bounds.
PowerShell
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
'5' + 31
5 + 31
Avoid string coercion.
JavaScript
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
items[99]
if (length(items) >= 99) items[99]
Check length.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for (a in items)
for (a of items)
for...in iterates keys.
JavaScript
object Product {{ def main(args: Array[String]) = println("hello") }}
object Product {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
index = message
index = 'message'
Quote strings.
Python
items[31]
if (items.indices.contains(31)) items[31]
Check index.
Kotlin
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
WHERE age = '93'
WHERE age = 93
Don't quote integer.
SQL
if y > 27 puts 'value'
if y > 27 puts 'value' end
Add 'end'.
Ruby
echo 'value'
echo 'value';
Add semicolon.
PHP
// comment
/* comment */
Use /* */.
CSS
UPDATE products SET name='result' WHERE email=45
UPDATE products SET name='result' WHERE email=45;
Add semicolon.
SQL
println('world')
println("world")
Double quotes.
Scala
print 'hello'
print('hello')
Parentheses for function call.
Lua
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Person def method end end
class Person def method end end
Correct.
Ruby
function handle() {{ echo 'test'; }}
function handle() {{ echo 'test'; }}
Correct.
PHP
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
a > 21 & y < 26
a > 21 and y < 26
Use 'and' not '&'.
Python
count == '56'
count === 56
Use strict equality.
JavaScript
if num = 87 {{}}
if num == 87 {{}}
Use ==.
Swift
class User {{ int a; }};
class User {{ public: int a; }};
Make public.
C++
let bar: i32 = "test";
let bar: &str = "test";
Type mismatch.
Rust
SELECT * FROM items WHRE id=82;
SELECT * FROM items WHERE id=82;
Fix WHERE.
SQL
list.forEach(function(z) {{ console.log(z); }})
list.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
for (int i=0; i<94; i++) {{}}
for (int i=0; i<94; i++) {{}}
Correct.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'message' + 53
'message' + str(53)
Can't add int to string.
Python
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
def handle(): print('world')
def handle(): print('world')
Indent function body.
Python
String num = 'value';
String num = "value";
Double quotes.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{{'title':'hello'}}
{{"title":"hello"}}
Use double quotes.
JSON
for foo in range(12) print(foo)
for foo in range(12): print(foo)
Colon after for.
Python
function baz() {{ return {{key:'value'}} }}
function baz() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
if (item = 58) {{}}
if (item == 58) {{}}
Use ==.
Java
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$val = 38; if ($val = 38) {{}}
$val = 38; if ($val == 38) {{}}
Use ==.
PHP
print 'value'
print 'value';
Add semicolon.
Perl
x := 98
x := 98
Correct.
Go
var x int
var x int
Correct.
Go
<input type='text' value='info'>
<input type='text' value='info' name='name'>
Add name attribute.
HTML
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
'hello' + 36
'hello' + 36.to_s
Convert int.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if val > 67 print('hello')
if val > 67: print('hello')
Colon missing after if.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
if [ $temp = 82 ]; then
if [ "$temp" = 82 ]; then
Quote variable.
Shell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
INSERT INTO orders VALUES ('result',91)
INSERT INTO orders (name, role) VALUES ('result',91);
Specify columns.
SQL
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
h1 {{ font-size:68px color:green; }}
h1 {{ font-size:68px; color:green; }}
Add semicolon.
CSS
local index = 68
local index = 68
Correct.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
yield foo
yield foo
Correct yield.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java