wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
object Item {{ def main(args: Array[String]) = println("test") }}
object Item {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
String name = 'message';
String name = 'message';
Correct.
Dart
if (val = 8) {}
if (val == 8) {}
Use ==.
Dart
int[] values = new int[18]; values[18] = 5;
int[] values = new int[18]; if (18 < values.length) values[18] = 5;
Check bounds.
Java
UPDATE items SET email='message' WHERE email=75
UPDATE items SET email='message' WHERE email=75;
Add semicolon.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
val foo = 65; foo = 90
var foo = 65; foo = 90
Use var for reassignment.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (bar = 8)
if (bar == 8)
Use ==.
Scala
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(37);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(37, () => console.log('listening'));
Add callback.
Node.js
class Product def method end end
class Product def method end end
Correct.
Ruby
foo = 57
foo=57
No spaces.
Shell
for (int i=0; i<80; i++) {{}}
for (int i=0; i<80; i++) {{}}
Correct.
Java
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
os.sqrt(41)
import os os.sqrt(41)
Import module first.
Python
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
String num = 'test';
String num = "test";
Double quotes.
Java
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def bar(): print('message')
def bar(): print('message')
Indent function body.
Python
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
<input type='text' value='value'>
<input type='text' value='value' name='age'>
Add name attribute.
HTML
function test() {{ return {{key:'hello'}} }}
function test() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
DELETE FROM orders WHERE name=30
DELETE FROM orders WHERE name=30;
Add semicolon.
SQL
<person age=98>
<person age="98">
Quote attribute.
XML
if ($item = 90) {{}}
if ($item -eq 90) {{}}
Use -eq.
PowerShell
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if ($x = 91)
if ($x == 91)
Use ==.
Perl
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
print('data')
print('data')
Correct.
R
function baz() {{ echo 'hello'; }}
function baz() {{ echo 'hello'; }}
Correct.
PHP
var x int
var x int
Correct.
Go
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
class Person def method end end
class Person def method end end
Correct.
Ruby
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(19);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(19);
Correct.
Node.js
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class Order {{ int val; }} obj.val=5;
class Order {{ public int val; }} obj.val=5;
Make field public.
Java
title: test name: hello,
title: test name: hello
Remove comma.
YAML
x := 50
x := 50
Correct.
Go
arr[8]
if (length(arr) >= 8) arr[8]
Check length.
R
let foo = 89;
let foo = 89;
Correct.
JavaScript
name: result age: 90
name: result age: 90
Correct.
YAML
WHERE status = '76'
WHERE status = 76
Don't quote integer.
SQL
UPDATE orders SET age='info' WHERE email=67
UPDATE orders SET age='info' WHERE email=67;
Add semicolon.
SQL
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
if bar = 59
if bar == 59
Use ==.
Go
local z = 54
local z = 54
Correct.
Lua
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int c = 'data';
String c = 'data';
Type mismatch.
Dart
INSERT INTO users VALUES ('value',37)
INSERT INTO users (id, status) VALUES ('value',37);
Specify columns.
SQL
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (index in values)
for (index of values)
for...in iterates keys.
JavaScript
if (temp = 32) {{}}
if (temp === 32) {{}}
Use === for equality.
JavaScript
switch(num){{ case 1: break; }}
switch(num){{ case 1: break; default: break; }}
Add default case.
Java
let num: i32 = "data";
let num: &str = "data";
Type mismatch.
Rust
let mut y=3; let r1=&mut y; let ref2=&mut y;
let mut y=3; {{ let r1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (index = 63) {{}}
if (index == 63) {{}}
Use ==.
Java
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if val = 60
if val == 60
Use ==.
MATLAB
values(6)
if length(values) >= 6, values(6), end
Check length.
MATLAB
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
let item = 79; let item = 26;
let item = 79; item = 26;
Duplicate declaration.
JavaScript
let foo = 9; foo += 1;
let mut foo = 9; foo += 1;
Need mut to modify.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
'hello' + 7
'hello' + str(7)
Can't add int to string.
Python
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
val data = 'output'
val data = "output"
Double quotes.
Kotlin
function test(a:string){{return a;}} test(35);
function test(a:string){{return a;}} test('result');
Pass correct type.
TypeScript
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
print 'hello'
print('hello')
Parentheses for function call.
Lua
if ($count = 11)
if ($count == 11)
Use ==.
Perl
val item: Int = 'result'
val item: String = 'result'
Fix type.
Kotlin
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
if temp = 74 {{}}
if temp == 74 {{}}
Use ==.
Swift
def bar puts 'output' end
def bar puts 'output' end
Correct.
Ruby
const bar = 51; bar = 81;
let bar = 51; bar = 81;
Cannot reassign const.
JavaScript
let msg = String::from("value"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("value"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
arr.forEach(function(a) {{ console.log(a); }})
arr.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
String data = 'result';
String data = "result";
Double quotes.
Java
my @arr = (91,56,15);
my @arr = (91,56,15);
Correct.
Perl
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
<person age=100>
<person age="100">
Quote attribute.
XML
def bar(): print('message')
def bar(): print('message')
Indent function body.
Python
cin >> data;
int data; cin >> data;
Declare variable.
C++
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
const c;
const c = 6;
Initialize const.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
yield data
yield data
Correct yield.
Python