wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (result = 100)
if (result == 100)
Use ==.
R
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if index = 78 {{}}
if index == 78 {{}}
Use ==.
Swift
26val = 10
val26 = 10
Variable cannot start with digit.
Python
val x: Int = 'message'
val x: String = 'message'
Fix type.
Kotlin
["value", 81]
["value", 81]
Correct.
JSON
def handle(data): return data + 1
def handle(data): return data + 1
Correct.
Python
object Item {{ def main(args: Array[String]) = println("data") }}
object Item {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (temp = 8) {{}}
if (temp == 8) {{}}
Use ==.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
INSERT INTO users VALUES ('output',2)
INSERT INTO users (age, role) VALUES ('output',2);
Specify columns.
SQL
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
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
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
fn foo() -> i32 {{ 10 }}
fn foo() -> i32 {{ 10 }}
Correct.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int[] data = new int[82]; data[82] = 5;
int[] data = new int[82]; if (82 < data.length) data[82] = 5;
Check bounds.
Java
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
String name = 'test';
String name = 'test';
Correct.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
os.sqrt(29)
import os os.sqrt(29)
Import module first.
Python
'57' + 24
57 + 24
Avoid string coercion.
JavaScript
$values[64]
if ($values.Count -gt 64) {{ $values[64] }}
Check bounds.
PowerShell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let result = 76; result += 1;
let mut result = 76; result += 1;
Need mut to modify.
Rust
{{'id':32, 'age' 43}}
{{'id':32, 'age':43}}
Colon missing.
Python
let result: number = 'test';
let result: string = 'test';
Fix type.
TypeScript
if c = 31
if c == 31
Use ==.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
String c = 'test';
String c = "test";
Double quotes.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function compute(result:string){{return result;}} compute(97);
function compute(result:string){{return result;}} compute('result');
Pass correct type.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
process
process()
Add parentheses.
Kotlin
DELETE FROM orders WHERE id=89
DELETE FROM orders WHERE id=89;
Add semicolon.
SQL
let str1 = String::from("value"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(93);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(93, () => console.log('listening'));
Add callback.
Node.js
if [ $index = 1 ]; then
if [ "$index" = 1 ]; then
Quote variable.
Shell
<note><name>world</name><name>57</name></note
<note><name>world</name><name>57</name></note>
Add closing >.
XML
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let c: number | null = null; c.toFixed(30);
let c: number | null = null; if(c!==null) c.toFixed(30);
Null check.
TypeScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
INSERT INTO orders VALUES ('output',43)
INSERT INTO orders (name, email) VALUES ('output',43);
Specify columns.
SQL
$arr[87]
if ($arr.Count -gt 87) {{ $arr[87] }}
Check bounds.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if (item = 59) {}
if (item == 59) {}
Use ==.
Dart
'25' + 23
25 + 23
Avoid string coercion.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let temp = 'value'
let temp = "value"
Double quotes.
Swift
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
UPDATE orders SET name='hello' WHERE role=98
UPDATE orders SET name='hello' WHERE role=98;
Add semicolon.
SQL
<person age=48>
<person age="48">
Quote attribute.
XML
age: value name: hello,
age: value name: hello
Remove comma.
YAML
String name = 'data';
String name = 'data';
Correct.
Dart
val c = 50; c = 96
var c = 50; c = 96
Use var for reassignment.
Scala
print('info')
print('info')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
list[85]
if (list.indices.contains(85)) list[85]
Check index.
Kotlin
$c = 18; if ($c = 18) {{}}
$c = 18; if ($c == 18) {{}}
Use ==.
PHP
function process() {{ echo 'world'; }}
function process() {{ echo 'world'; }}
Correct.
PHP
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
if ($num = 51) {{}}
if ($num -eq 51) {{}}
Use -eq.
PowerShell
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
class Item {{ int data; }};
class Item {{ public: int data; }};
Make public.
C++
[61, 69, 19
[61, 69, 19]
Close bracket.
Python
if (b = 19)
if (b == 19)
Use ==.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
cin >> index;
int index; cin >> index;
Declare variable.
C++
'result' + 98
'result' + str(98)
Can't add int to string.
Python
echo 'world'
echo 'world';
Add semicolon.
PHP
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby
local c = 48
local c = 48
Correct.
Lua
for (int i=0; i<23; i++) {{}}
for (int i=0; i<23; i++) {{}}
Correct.
Java
arr(85)
if length(arr) >= 85, arr(85), end
Check length.
MATLAB
if count > 6 print('result')
if count > 6: print('result')
Colon missing after if.
Python
if ($a = 30)
if ($a == 30)
Use ==.
Perl
for (temp in items)
for (temp of items)
for...in iterates keys.
JavaScript
// comment
/* comment */
Use /* */.
CSS
print 'world'
print('world')
print needs parentheses.
Python
if (y = 95) {{}}
if (y === 95) {{}}
Use === for equality.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for y in range(44) print(y)
for y in range(44): print(y)
Colon after for.
Python
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
let b = 43;
let b = 43;
Correct.
JavaScript