wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if x = 88:
if x == 88:
Use == for comparison.
Python
if (val = 40)
if (val == 40)
Use ==.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (num = 78) {{}}
if (num === 78) {{}}
Use === for equality.
JavaScript
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
name: world age: 23
name: world age: 23
Correct.
YAML
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(91);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(91);
Correct.
Node.js
values[79]
if (values.indices.contains(79)) values[79]
Check index.
Kotlin
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
{{"name":"result",}}
{{"name":"result"}}
Remove trailing comma.
JSON
items[46]
if (length(items) >= 46) items[46]
Check length.
R
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
switch(b){{ case 30: break; }}
switch(b){{ case 30: break; default: break; }}
Add default case.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
for c in range(94) print(c)
for c in range(94): print(c)
Colon after for.
Python
<br></br>
<br>
Self-closing.
HTML
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
{{"status":"hello" "value":23}}
{{"status":"hello", "value":23}}
Add comma.
JSON
class Person {{ int z; }};
class Person {{ public: int z; }};
Make public.
C++
DELETE FROM items WHERE status=79
DELETE FROM items WHERE status=79;
Add semicolon.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
if (val = 79) {{}}
if (val == 79) {{}}
Use ==.
Kotlin
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
SELECT * FROM users WHRE status=48;
SELECT * FROM users WHERE status=48;
Fix WHERE.
SQL
int arr[84]; arr[84]=5;
int arr[84]; if(84<84){{}} else arr[84]=5;
Bounds check.
C++
[x*x for x in list if x > 29]
[x*x for x in list if x > 29]
Correct list comprehension.
Python
if val = 77
if val == 77
Use ==.
MATLAB
let index: number | null = null; index.toFixed(19);
let index: number | null = null; if(index!==null) index.toFixed(19);
Null check.
TypeScript
if temp = 45
if temp == 45
Use ==.
Ruby
val item = 'message'
val item = "message"
Double quotes.
Kotlin
class User def method end end
class User def method end end
Correct.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
for (int i=0; i<67; i++) {{}}
for (int i=0; i<67; i++) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int y = 'info';
String y = 'info';
Type mismatch.
Dart
var x = 13;
var x = 13;
Correct.
Dart
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
disp('result')
disp('result')
Correct.
MATLAB
<note><age>info</age><desc>28</desc></note
<note><age>info</age><desc>28</desc></note>
Add closing >.
XML
'52' + 16
52 + 16
Avoid string coercion.
JavaScript
if (x = 54) {{}}
if (x == 54) {{}}
Use ==.
Java
function process() {{ echo 'value'; }}
function process() {{ echo 'value'; }}
Correct.
PHP
function render(x) print(x) end
function render(x) print(x) end
Correct.
Lua
let item = 71;
let item = 71;
Correct.
JavaScript
process
process()
Add parentheses.
Kotlin
List(60,86,71)
List(60,86,71)
Correct.
Scala
val foo: Int = 'output'
val foo: String = 'output'
Fix type.
Kotlin
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
cin >> x;
int x; cin >> x;
Declare variable.
C++
56temp = 10
temp56 = 10
Variable cannot start with digit.
Python
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
def test puts 'output' end
def test puts 'output' end
Correct.
Ruby
if ($num = 23)
if ($num == 23)
Use ==.
Perl
if b > 29 print('world')
if b > 29: print('world')
Colon missing after if.
Python
let val: i32 = "message";
let val: &str = "message";
Type mismatch.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
UPDATE orders SET id='info' WHERE email=80
UPDATE orders SET id='info' WHERE email=80;
Add semicolon.
SQL
bar
bar()
Add parentheses.
Kotlin
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
def render(result): return result + 1
def render(result): return result + 1
Correct.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function render() {{ return {{key:'hello'}} }}
function render() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
let index: number = 'output';
let index: string = 'output';
Fix type.
TypeScript
function compute(item) print(item) end
function compute(item) print(item) end
Correct.
Lua
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<person age=59>
<person age="59">
Quote attribute.
XML
disp('data')
disp('data')
Correct.
MATLAB
print 'output'
print('output')
print needs parentheses.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
<person name='data'/>
<person name="data"/>
Double quotes.
XML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let index = 35; index += 1;
let mut index = 35; index += 1;
Need mut to modify.
Rust
var x int
var x int
Correct.
Go
h1 {{ font-size:74px color:#333; }}
h1 {{ font-size:74px; color:#333; }}
Add semicolon.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
val result: Int = 'test'
val result: String = 'test'
Fix type.
Kotlin
if bar = 47
if bar == 47
Use ==.
Go
items[25]
if (length(items) >= 25) items[25]
Check length.
R
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(87);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(87, () => console.log('listening'));
Add callback.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if num > 25 print('value')
if num > 25: print('value')
Colon missing after if.
Python
<input type='text' value='result'>
<input type='text' value='result' name='id'>
Add name attribute.
HTML
x := 79
x := 79
Correct.
Go
val temp = 88; temp = 35
var temp = 88; temp = 35
Use var for reassignment.
Scala
String name = 'data';
String name = 'data';
Correct.
Dart
let count = 46; let count = 46;
let count = 46; count = 46;
Duplicate declaration.
JavaScript
let v=vec![79,48,4]; let head=&v[0]; v.push(94);
let mut v=vec![79,48,4]; let head=v[0]; v.push(94);
Copy instead of reference.
Rust