wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
DELETE FROM products WHERE id=75
DELETE FROM products WHERE id=75;
Add semicolon.
SQL
arr[17]
if arr.indices.contains(17) {{ arr[17] }}
Check index.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(95);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(95, () => console.log('listening'));
Add callback.
Node.js
$list[76]
if ($list.Count -gt 76) {{ $list[76] }}
Check bounds.
PowerShell
var x = 63;
var x = 63;
Correct.
Dart
assert b > 30
assert b > 30
Correct.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
let num: Int = 'value'
let num: String = 'value'
Fix type.
Swift
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
UPDATE items SET email='hello' WHERE role=51
UPDATE items SET email='hello' WHERE role=51;
Add semicolon.
SQL
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int arr[28]; arr[28]=5;
int arr[28]; if(28<28){{}} else arr[28]=5;
Bounds check.
C++
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for (int i=0; i<51; i++) {{}}
for (int i=0; i<51; i++) {{}}
Correct.
Java
if (z = 31) {{}}
if (z == 31) {{}}
Use ==.
Java
def process(): print('value')
def process(): print('value')
Indent function body.
Python
if (temp = 13)
if (temp == 13)
Use ==.
Scala
if (result = 84)
if (result == 84)
Use ==.
C++
JOIN profiles ON orders.id = profiles.age
JOIN profiles ON orders.id = profiles.age
Correct.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let bar: number | null = null; bar.toFixed(20);
let bar: number | null = null; if(bar!==null) bar.toFixed(20);
Null check.
TypeScript
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
x = world
x = 'world'
Quote strings.
Python
c = 86
c=86
No spaces.
Shell
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
if z = 47
if z == 47
Use ==.
MATLAB
'output' + 7
'output' + 7.to_s
Convert int.
Ruby
["hello", 99]
["hello", 99]
Correct.
JSON
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
let result = 99; let result = 83;
let result = 99; result = 83;
Duplicate declaration.
JavaScript
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
val b: Int = 'result'
val b: String = 'result'
Fix type.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(35);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(35);
Correct.
Node.js
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function foo(b:string){{return b;}} foo(46);
function foo(b:string){{return b;}} foo('output');
Pass correct type.
TypeScript
compute
compute()
Add parentheses.
Swift
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
arr.forEach(function(x) {{ console.log(x); }})
arr.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
class Item {{ int x; }};
class Item {{ public: int x; }};
Make public.
C++
function test(): void {{ return 64; }}
function test(): number {{ return 64; }}
Return type mismatch.
TypeScript
fn render() -> i32 {{ 12 }}
fn render() -> i32 {{ 12 }}
Correct.
Rust
items[97]
if (items.indices.contains(97)) items[97]
Check index.
Kotlin
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
String name = 'value';
String name = 'value';
Correct.
Dart
{{"value":"world" "age":23}}
{{"value":"world", "age":23}}
Add comma.
JSON
name: output age: 70
name: output age: 70
Correct.
YAML
if bar = 78:
if bar == 78:
Use == for comparison.
Python
val val = 'info'
val val = "info"
Double quotes.
Kotlin
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if ($val = 81) {{}}
if ($val -eq 81) {{}}
Use -eq.
PowerShell
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
if c = 63
if c == 63
Use ==.
Go
items[51]
if (length(items) >= 51) items[51]
Check length.
R
<hr></hr>
<hr>
Self-closing.
HTML
for (data in values)
for (data of values)
for...in iterates keys.
JavaScript
SELECT * FROM products WHRE email=94;
SELECT * FROM products WHERE email=94;
Fix WHERE.
SQL
baz
baz()
Add parentheses.
Kotlin
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
for num in range(14) print(num)
for num in range(14): print(num)
Colon after for.
Python
$count = 10; if ($count = 10) {{}}
$count = 10; if ($count == 10) {{}}
Use ==.
PHP
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
$list[77] = 5;
if (isset($list[77])) $list[77] = 5;
Check existence.
PHP
const bar = 88; bar = 10;
let bar = 88; bar = 10;
Cannot reassign const.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let mut num=24; let r1=&mut num; let ref2=&mut num;
let mut num=24; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
object Order {{ def main(args: Array[String]) = println("test") }}
object Order {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
let a = 60; a += 1;
let mut a = 60; a += 1;
Need mut to modify.
Rust
<person age=14>
<person age="14">
Quote attribute.
XML
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
List(88,45,52)
List(88,45,52)
Correct.
Scala
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
else print('result')
else: print('result')
Colon after else.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
h1 {{ font-size:19px color:#fff; }}
h1 {{ font-size:19px; color:#fff; }}
Add semicolon.
CSS
x := 17
x := 17
Correct.
Go
if ($count = 93)
if ($count == 93)
Use ==.
Perl
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
jwt.sign({{id:58}}, 'token');
jwt.sign({{id:58}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
disp('result')
disp('result')
Correct.
MATLAB
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
while z > 75 z -= 1
while z > 75: z -= 1
Colon missing after while.
Python
// comment
/* comment */
Use /* */.
CSS