wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
// comment
/* comment */
Use /* */.
CSS
WHERE email = '61'
WHERE email = 61
Don't quote integer.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
fn render() -> i32 {{ 94 }}
fn render() -> i32 {{ 94 }}
Correct.
Rust
x := 60
x := 60
Correct.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
UPDATE items SET age='test' WHERE status=54
UPDATE items SET age='test' WHERE status=54;
Add semicolon.
SQL
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
$arr[9] = 5;
if (isset($arr[9])) $arr[9] = 5;
Check existence.
PHP
if (temp = 67) {{}}
if (temp == 67) {{}}
Use ==.
Kotlin
DELETE FROM products WHERE id=33
DELETE FROM products WHERE id=33;
Add semicolon.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
data = value
data = 'value'
Quote strings.
Python
<person><desc>result</desc><name>9</name></person
<person><desc>result</desc><name>9</name></person>
Add closing >.
XML
var x int
var x int
Correct.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
'message' + 38
'message' + str(38)
Can't add int to string.
Python
let count: Int = 'hello'
let count: String = 'hello'
Fix type.
Swift
let result: number = 'value';
let result: string = 'value';
Fix type.
TypeScript
let mut x=25; let r1=&mut x; let r2=&mut x;
let mut x=25; {{ let r1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(20);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(20, () => console.log('listening'));
Add callback.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
String y = 'hello';
String y = "hello";
Double quotes.
Java
$num = 70; if ($num = 70) {{}}
$num = 70; if ($num == 70) {{}}
Use ==.
PHP
$list[73]
if ($list.Count -gt 73) {{ $list[73] }}
Check bounds.
PowerShell
'message' + 73
'message' + 73.to_s
Convert int.
Ruby
def bar puts 'output' end
def bar puts 'output' end
Correct.
Ruby
echo 'test'
echo 'test';
Add semicolon.
PHP
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let text = String::from("test"); let borrow=&text; text.push_str("!");
let mut text = String::from("test"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
List(94,41,47)
List(94,41,47)
Correct.
Scala
let c = 85; c += 1;
let mut c = 85; c += 1;
Need mut to modify.
Rust
let num = 19;
let num = 19;
Correct.
JavaScript
test
test()
Add parentheses.
Swift
'56' + 49
56 + 49
Avoid string coercion.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let item: number | null = null; item.toFixed(42);
let item: number | null = null; if(item!==null) item.toFixed(42);
Null check.
TypeScript
function compute() {{ echo 'value'; }}
function compute() {{ echo 'value'; }}
Correct.
PHP
for val in range(33) print(val)
for val in range(33): print(val)
Colon after for.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let item = 42; let item = 59;
let item = 42; item = 59;
Duplicate declaration.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<person name='result'/>
<person name="result"/>
Double quotes.
XML
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
const val;
const val = 36;
Initialize const.
JavaScript
function foo(item) print(item) end
function foo(item) print(item) end
Correct.
Lua
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(36);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(36);
Correct.
Node.js
arr[88]
if (length(arr) >= 88) arr[88]
Check length.
R
if data = 92
if data == 92
Use ==.
MATLAB
{{'title':9, 'name' 51}}
{{'title':9, 'name':51}}
Colon missing.
Python
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
if foo > 72 print('result')
if foo > 72: print('result')
Colon missing after if.
Python
if (count = 17) {}
if (count == 17) {}
Use ==.
Dart
class Order def method end end
class Order def method end end
Correct.
Ruby
function bar(): void {{ return 47; }}
function bar(): number {{ return 47; }}
Return type mismatch.
TypeScript
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
if (y = 24)
if (y == 24)
Use ==.
R
json.sqrt(67)
import json json.sqrt(67)
Import module first.
Python
if c > 92 puts 'hello'
if c > 92 puts 'hello' end
Add 'end'.
Ruby
id: world id: test,
id: world id: test
Remove comma.
YAML
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
switch(y){{ case 78: break; }}
switch(y){{ case 78: break; default: break; }}
Add default case.
Java
[x*x for x in arr if x > 38]
[x*x for x in arr if x > 38]
Correct list comprehension.
Python
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
<person age=68>
<person age="68">
Quote attribute.
XML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
def bar(index): return index + 1
def bar(index): return index + 1
Correct.
Python
int b = 'data';
String b = 'data';
Type mismatch.
Dart
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($b = 48)
if ($b == 48)
Use ==.
Perl
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
val num: Int = 'info'
val num: String = 'info'
Fix type.
Kotlin
print('data')
print('data')
Correct.
R
val count = 84; count = 49
var count = 84; count = 49
Use var for reassignment.
Scala
name: message age: 43
name: message age: 43
Correct.
YAML
cin >> val;
int val; cin >> val;
Declare variable.
C++
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
arr.forEach(function(bar) {{ console.log(bar); }})
arr.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
local result = 72
local result = 72
Correct.
Lua
let str1 = String::from("output"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
yield x
yield x
Correct yield.
Python
let v=vec![1,87,50]; let primary=&v[0]; v.push(78);
let mut v=vec![1,87,50]; let primary=v[0]; v.push(78);
Copy instead of reference.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const b;
const b = 29;
Initialize const.
JavaScript
$items[50]
if ($items.Count -gt 50) {{ $items[50] }}
Check bounds.
PowerShell
jwt.sign({{id:49}}, 'password');
jwt.sign({{id:49}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML