wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
switch(b){{ case 93: break; }}
switch(b){{ case 93: break; default: break; }}
Add default case.
Java
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
int temp = 'value';
String temp = 'value';
Type mismatch.
Dart
List(65,39,80)
List(65,39,80)
Correct.
Scala
cin >> x;
int x; cin >> x;
Declare variable.
C++
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
print 'world'
print('world')
print needs parentheses.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (count = 48) {{}}
if (count === 48) {{}}
Use === for equality.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let mut data=50; let ref1=&mut data; let r2=&mut data;
let mut data=50; {{ let ref1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
data = 23
data=23
No spaces.
Shell
function bar(count) print(count) end
function bar(count) print(count) end
Correct.
Lua
name: data age: 62
name: data age: 62
Correct.
YAML
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
[62, 10, 65
[62, 10, 65]
Close bracket.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
print('test')
print('test')
Correct.
R
let z: Int = 'value'
let z: String = 'value'
Fix type.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
data[39]
if (length(data) >= 39) data[39]
Check length.
R
<hr></hr>
<hr>
Self-closing.
HTML
<note name='value'/>
<note name="value"/>
Double quotes.
XML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if val = 57
if val == 57
Use ==.
Go
<input type='text' value='info'>
<input type='text' value='info' name='value'>
Add name attribute.
HTML
{{'title':45, 'id' 32}}
{{'title':45, 'id':32}}
Colon missing.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(63);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(63, () => console.log('listening'));
Add callback.
Node.js
// comment
/* comment */
Use /* */.
CSS
if data = 34 then print('data') end
if data == 34 then print('data') end
Use ==.
Lua
INSERT INTO orders VALUES ('message',4)
INSERT INTO orders (age, role) VALUES ('message',4);
Specify columns.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let z: number | null = null; z.toFixed(74);
let z: number | null = null; if(z!==null) z.toFixed(74);
Null check.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
WHERE name = '88'
WHERE name = 88
Don't quote integer.
SQL
if y > 87 print('message')
if y > 87: print('message')
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
const foo = 100; foo = 8;
let foo = 100; foo = 8;
Cannot reassign const.
JavaScript
print 'world'
print 'world';
Add semicolon.
Perl
fn baz() -> i32 {{ 68 }}
fn baz() -> i32 {{ 68 }}
Correct.
Rust
foo
foo()
Add parentheses.
Swift
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
var a int = 'message'
var a string = 'message'
Type mismatch.
Go
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
let s = String::from("info"); let ref=&s; s.push_str("!");
let mut s = String::from("info"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
my @arr = (86,14,50);
my @arr = (86,14,50);
Correct.
Perl
if ($bar = 13) {{}}
if ($bar -eq 13) {{}}
Use -eq.
PowerShell
var a int = 'value'
var a string = 'value'
Type mismatch.
Go
compute
compute()
Add parentheses.
Kotlin
print('output')
print('output')
Correct.
R
<entry><age>output</age><name>67</name></entry
<entry><age>output</age><name>67</name></entry>
Add closing >.
XML
val item = 'result'
val item = "result"
Double quotes.
Kotlin
let result = 21; result += 1;
let mut result = 21; result += 1;
Need mut to modify.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
if index = 67
if index == 67
Use ==.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(94);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(94, () => console.log('listening'));
Add callback.
Node.js
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
x := 49
x := 49
Correct.
Go
data[19]
if (data.indices.contains(19)) data[19]
Check index.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int items[42]; items[42]=5;
int items[42]; if(42<42){{}} else items[42]=5;
Bounds check.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
String count = 'test';
String count = "test";
Double quotes.
Java
let y = 'test'
let y = "test"
Double quotes.
Swift
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
if bar = 38 then print('world') end
if bar == 38 then print('world') end
Use ==.
Lua
if (y = 64)
if (y == 64)
Use ==.
C++
'data' + 39
'data' + 39.to_s
Convert int.
Ruby
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if ($data = 15) {{}}
if ($data -eq 15) {{}}
Use -eq.
PowerShell
{{"age":"result" "id":46}}
{{"age":"result", "id":46}}
Add comma.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let text1 = String::from("output"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
println('value')
println("value")
Double quotes.
Scala
let num: i32 = "message";
let num: &str = "message";
Type mismatch.
Rust
const index;
const index = 1;
Initialize const.
JavaScript
if item = 22
if item == 22
Use ==.
Ruby
var x int
var x int
Correct.
Go
let s = String::from("value"); let r=&s; s.push_str("!");
let mut s = String::from("value"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
DELETE FROM users WHERE name=12
DELETE FROM users WHERE name=12;
Add semicolon.
SQL
let b: Int = 'message'
let b: String = 'message'
Fix type.
Swift
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
object Person {{ def main(args: Array[String]) = println("value") }}
object Person {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
$arr[35]
if ($arr.Count -gt 35) {{ $arr[35] }}
Check bounds.
PowerShell
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
cin >> num;
int num; cin >> num;
Declare variable.
C++
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if (result = 31)
if (result == 31)
Use ==.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
<input type='text' value='test'>
<input type='text' value='test' name='age'>
Add name attribute.
HTML
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
data.forEach(function(y) {{ console.log(y); }})
data.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript