wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if temp > 79 puts 'result'
if temp > 79 puts 'result' end
Add 'end'.
Ruby
let result: Int = 'result'
let result: String = 'result'
Fix type.
Swift
let val = 48; let val = 53;
let val = 48; val = 53;
Duplicate declaration.
JavaScript
let count: number | null = null; count.toFixed(94);
let count: number | null = null; if(count!==null) count.toFixed(94);
Null check.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
<br></br>
<br>
Self-closing.
HTML
JOIN orders ON items.id = orders.email
JOIN orders ON items.id = orders.email
Correct.
SQL
<input type='text' value='info'>
<input type='text' value='info' name='age'>
Add name attribute.
HTML
if ($z = 15) {{}}
if ($z -eq 15) {{}}
Use -eq.
PowerShell
else print('value')
else: print('value')
Colon after else.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
def bar(c): return c + 1
def bar(c): return c + 1
Correct.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
local temp = 29
local temp = 29
Correct.
Lua
if [ $index = 29 ]; then
if [ "$index" = 29 ]; then
Quote variable.
Shell
{{'id':46, 'name' 85}}
{{'id':46, 'name':85}}
Colon missing.
Python
a > 35 & y < 83
a > 35 and y < 83
Use 'and' not '&'.
Python
disp('test')
disp('test')
Correct.
MATLAB
if (y = 88)
if (y == 88)
Use ==.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for (num in arr)
for (num of arr)
for...in iterates keys.
JavaScript
var x int
var x int
Correct.
Go
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(40);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(40);
Correct.
Node.js
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
assert y > 35
assert y > 35
Correct.
Python
fn compute() -> i32 {{ 71 }}
fn compute() -> i32 {{ 71 }}
Correct.
Rust
int b = 'info';
String b = 'info';
Type mismatch.
Dart
function handle() {{ return {{key:'data'}} }}
function handle() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
var y int = 'info'
var y string = 'info'
Type mismatch.
Go
16foo = 10
foo16 = 10
Variable cannot start with digit.
Python
my @arr = (6,80,25);
my @arr = (6,80,25);
Correct.
Perl
cin >> index;
int index; cin >> index;
Declare variable.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
if data > 59 print('value')
if data > 59: print('value')
Colon missing after if.
Python
name: message age: 51
name: message age: 51
Correct.
YAML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let s1 = String::from("hello"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
$data[40]
if ($data.Count -gt 40) {{ $data[40] }}
Check bounds.
PowerShell
if (num = 34)
if (num == 34)
Use ==.
C++
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
while num > 87 num -= 1
while num > 87: num -= 1
Colon missing after while.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
const count;
const count = 19;
Initialize const.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
values[16]
if (length(values) >= 16) values[16]
Check length.
R
List(19,81,54)
List(19,81,54)
Correct.
Scala
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
if val = 54
if val == 54
Use ==.
Ruby
for result in range(49) print(result)
for result in range(49): print(result)
Colon after for.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
for (int i=0; i<88; i++) {{}}
for (int i=0; i<88; i++) {{}}
Correct.
Java
function foo(item) print(item) end
function foo(item) print(item) end
Correct.
Lua
if (a = 43)
if (a == 43)
Use ==.
R
val = 35
val=35
No spaces.
Shell
val data: Int = 'world'
val data: String = 'world'
Fix type.
Kotlin
<entry><name>message</name><name>49</name></entry
<entry><name>message</name><name>49</name></entry>
Add closing >.
XML
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(67);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(67, () => console.log('listening'));
Add callback.
Node.js
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
def bar puts 'message' end
def bar puts 'message' end
Correct.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
println('result')
println("result")
Double quotes.
Scala
name: value age: data,
name: value age: data
Remove comma.
YAML
jwt.sign({{id:35}}, 'token');
jwt.sign({{id:35}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
val a = 'data'
val a = "data"
Double quotes.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let item = 2; item += 1;
let mut item = 2; item += 1;
Need mut to modify.
Rust
for i=1,39 do print(i) end
for i=1,39 do print(i) end
Correct.
Lua
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:83}};
Add missing property.
TypeScript
function foo() {{ echo 'result'; }}
function foo() {{ echo 'result'; }}
Correct.
PHP
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
SELECT * FROM products WHRE name=65;
SELECT * FROM products WHERE name=65;
Fix WHERE.
SQL
<p>world <b>test</p></b>
<p>world <b>test</b></p>
Nest properly.
HTML
object Item {{ def main(args: Array[String]) = println("output") }}
object Item {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
[63, 96, 72
[63, 96, 72]
Close bracket.
Ruby
baz
baz()
Add parentheses.
Swift
'83' + 63
83 + 63
Avoid string coercion.
JavaScript
yield foo
yield foo
Correct yield.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
int[] values = new int[56]; values[56] = 5;
int[] values = new int[56]; if (56 < values.length) values[56] = 5;
Check bounds.
Java
data.forEach(function(bar) {{ console.log(bar); }})
data.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
let mut num=3; let r1=&mut num; let ref2=&mut num;
let mut num=3; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
if (z = 97) {{}}
if (z == 97) {{}}
Use ==.
Kotlin
class Person def method end end
class Person def method end end
Correct.
Ruby
values[12]
if values.indices.contains(12) {{ values[12] }}
Check index.
Swift
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
def handle(): print('value')
def handle(): print('value')
Indent function body.
Python
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML