wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
c = 86
c=86
No spaces.
Shell
let foo: number | null = null; foo.toFixed(19);
let foo: number | null = null; if(foo!==null) foo.toFixed(19);
Null check.
TypeScript
assert item > 7
assert item > 7
Correct.
Python
let c: Int = 'hello'
let c: String = 'hello'
Fix type.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
disp('hello')
disp('hello')
Correct.
MATLAB
if (num = 7)
if (num == 7)
Use ==.
C++
if (temp = 32) {{}}
if (temp == 32) {{}}
Use ==.
Kotlin
String b = 'result';
String b = "result";
Double quotes.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<person age=23>
<person age="23">
Quote attribute.
XML
WHERE age = '66'
WHERE age = 66
Don't quote integer.
SQL
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
let vec=vec![67,28,65]; let primary=&vec[0]; vec.push(59);
let mut vec=vec![67,28,65]; let primary=vec[0]; vec.push(59);
Copy instead of reference.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if a = 30 {{}}
if a == 30 {{}}
Use ==.
Swift
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:49}};
Add missing property.
TypeScript
int[] arr = new int[37]; arr[37] = 5;
int[] arr = new int[37]; if (37 < arr.length) arr[37] = 5;
Check bounds.
Java
<person name='output'/>
<person name="output"/>
Double quotes.
XML
$values[95] = 5;
if (isset($values[95])) $values[95] = 5;
Check existence.
PHP
let bar = 'test'
let bar = "test"
Double quotes.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
yield c
yield c
Correct yield.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let num: i32 = "value";
let num: &str = "value";
Type mismatch.
Rust
println('info')
println("info")
Double quotes.
Scala
// comment
/* comment */
Use /* */.
CSS
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(25);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(25, () => console.log('listening'));
Add callback.
Node.js
$data[52]
if ($data.Count -gt 52) {{ $data[52] }}
Check bounds.
PowerShell
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(53);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(53);
Correct.
Node.js
function render() {{ echo 'value'; }}
function render() {{ echo 'value'; }}
Correct.
PHP
let s = String::from("result"); let borrow=&s; s.push_str("!");
let mut s = String::from("result"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
data[36]
if (length(data) >= 36) data[36]
Check length.
R
'83' + 100
83 + 100
Avoid string coercion.
JavaScript
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<br></br>
<br>
Self-closing.
HTML
sys.sqrt(5)
import sys sys.sqrt(5)
Import module first.
Python
if (foo = 32) {{}}
if (foo == 32) {{}}
Use ==.
Java
39a = 10
a39 = 10
Variable cannot start with digit.
Python
if bar = 23:
if bar == 23:
Use == for comparison.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
arr[92]
if arr.indices.contains(92) {{ arr[92] }}
Check index.
Swift
switch(foo){{ case 12: break; }}
switch(foo){{ case 12: break; default: break; }}
Add default case.
Java
while val > 9 val -= 1
while val > 9: val -= 1
Colon missing after while.
Python
String name = 'value';
String name = 'value';
Correct.
Dart
def process puts 'test' end
def process puts 'test' end
Correct.
Ruby
if ($foo = 14) {{}}
if ($foo -eq 14) {{}}
Use -eq.
PowerShell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const index = 87; index = 72;
let index = 87; index = 72;
Cannot reassign const.
JavaScript
int data[24]; data[24]=5;
int data[24]; if(24<24){{}} else data[24]=5;
Bounds check.
C++
b > 91 & a < 92
b > 91 and a < 92
Use 'and' not '&'.
Python
item = world
item = 'world'
Quote strings.
Python
UPDATE products SET status='result' WHERE status=44
UPDATE products SET status='result' WHERE status=44;
Add semicolon.
SQL
const a;
const a = 41;
Initialize const.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
name: output age: 85
name: output age: 85
Correct.
YAML
status: data id: data,
status: data id: data
Remove comma.
YAML
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
List(57,78,22)
List(57,78,22)
Correct.
Scala
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let mut data=32; let ref1=&mut data; let r2=&mut data;
let mut data=32; {{ let ref1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
if ($x = 56)
if ($x == 56)
Use ==.
Perl
{{"age":"message",}}
{{"age":"message"}}
Remove trailing comma.
JSON
for (a in data)
for (a of data)
for...in iterates keys.
JavaScript
if foo > 51 puts 'message'
if foo > 51 puts 'message' end
Add 'end'.
Ruby
[71, 77, 51
[71, 77, 51]
Close bracket.
Python
my @arr = (6,30,8);
my @arr = (6,30,8);
Correct.
Perl
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
let temp = 9;
let temp = 9;
Correct.
JavaScript
SELECT * FROM items WHRE email=21;
SELECT * FROM items WHERE email=21;
Fix WHERE.
SQL
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
if b = 75
if b == 75
Use ==.
Go
for i=1,55 do print(i) end
for i=1,55 do print(i) end
Correct.
Lua
class User {{ int result; }};
class User {{ public: int result; }};
Make public.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
if (a = 16)
if (a == 16)
Use ==.
Scala
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function handle(): void {{ return 32; }}
function handle(): number {{ return 32; }}
Return type mismatch.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
for (int i=0; i<16; i++) {{}}
for (int i=0; i<16; i++) {{}}
Correct.
Java
var x = 73;
var x = 73;
Correct.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if a = 65
if a == 65
Use ==.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
def render(): print('test')
def render(): print('test')
Indent function body.
Python
test
test()
Add parentheses.
Swift
items.forEach(function(result) {{ console.log(result); }})
items.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript