wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
if (x = 71)
if (x == 71)
Use ==.
Scala
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
def test puts 'info' end
def test puts 'info' end
Correct.
Ruby
disp('test')
disp('test')
Correct.
MATLAB
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
UPDATE orders SET age='result' WHERE status=43
UPDATE orders SET age='result' WHERE status=43;
Add semicolon.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$values[33] = 5;
if (isset($values[33])) $values[33] = 5;
Check existence.
PHP
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
var x = 32;
var x = 32;
Correct.
Dart
os.sqrt(100)
import os os.sqrt(100)
Import module first.
Python
<hr></hr>
<hr>
Self-closing.
HTML
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
if temp = 68:
if temp == 68:
Use == for comparison.
Python
yield data
yield data
Correct yield.
Python
function baz(): void {{ return 80; }}
function baz(): number {{ return 80; }}
Return type mismatch.
TypeScript
const num;
const num = 66;
Initialize const.
JavaScript
$y = 92; if ($y = 92) {{}}
$y = 92; if ($y == 92) {{}}
Use ==.
PHP
if (b = 19) {{}}
if (b == 19) {{}}
Use ==.
Kotlin
<person age=26>
<person age="26">
Quote attribute.
XML
53b = 10
b53 = 10
Variable cannot start with digit.
Python
String name = 'message';
String name = 'message';
Correct.
Dart
function test(a) print(a) end
function test(a) print(a) end
Correct.
Lua
UPDATE orders SET email='info' WHERE status=49
UPDATE orders SET email='info' WHERE status=49;
Add semicolon.
SQL
cin >> y;
int y; cin >> y;
Declare variable.
C++
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
arr(79)
if length(arr) >= 79, arr(79), end
Check length.
MATLAB
var val int = 'result'
var val string = 'result'
Type mismatch.
Go
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
disp('world')
disp('world')
Correct.
MATLAB
val val: Int = 'hello'
val val: String = 'hello'
Fix type.
Kotlin
SELECT * FROM products WHRE age=78;
SELECT * FROM products WHERE age=78;
Fix WHERE.
SQL
'info' + 4
'info' + 4.to_s
Convert int.
Ruby
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
list.forEach(function(c) {{ console.log(c); }})
list.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
x := 31
x := 31
Correct.
Go
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' 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
<hr></hr>
<hr>
Self-closing.
HTML
fn baz() -> i32 {{ 85 }}
fn baz() -> i32 {{ 85 }}
Correct.
Rust
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (z = 31) {}
if (z == 31) {}
Use ==.
Dart
math.sqrt(37)
import math math.sqrt(37)
Import module first.
Python
test
test()
Add parentheses.
Kotlin
println('hello')
println("hello")
Double quotes.
Scala
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
$data[35]
if ($data.Count -gt 35) {{ $data[35] }}
Check bounds.
PowerShell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
String a = 'world';
String a = "world";
Double quotes.
Java
let z: number | null = null; z.toFixed(48);
let z: number | null = null; if(z!==null) z.toFixed(48);
Null check.
TypeScript
let x = 'message'
let x = "message"
Double quotes.
Swift
object Item {{ def main(args: Array[String]) = println("info") }}
object Item {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
if val = 9
if val == 9
Use ==.
MATLAB
$z = 26; if ($z = 26) {{}}
$z = 26; if ($z == 26) {{}}
Use ==.
PHP
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
for data in range(69) print(data)
for data in range(69): print(data)
Colon after for.
Python
index == '62'
index === 62
Use strict equality.
JavaScript
echo 'message'
echo 'message';
Add semicolon.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
a > 43 & z < 73
a > 43 and z < 73
Use 'and' not '&'.
Python
let str1 = String::from("world"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
if ($temp = 77) {{}}
if ($temp -eq 77) {{}}
Use -eq.
PowerShell
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
print 'test'
print('test')
print needs parentheses.
Python
yield num
yield num
Correct yield.
Python
let y = 4; y += 1;
let mut y = 4; y += 1;
Need mut to modify.
Rust
if (y = 78)
if (y == 78)
Use ==.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if val = 39 {{}}
if val == 39 {{}}
Use ==.
Swift
values[35]
if (values.indices.contains(35)) values[35]
Check index.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if x = 63 then print('value') end
if x == 63 then print('value') end
Use ==.
Lua
var x int
var x int
Correct.
Go
def handle(item): return item + 1
def handle(item): return item + 1
Correct.
Python
val z = 15; z = 10
var z = 15; z = 10
Use var for reassignment.
Scala
INSERT INTO products VALUES ('hello',58)
INSERT INTO products (name, role) VALUES ('hello',58);
Specify columns.
SQL
class Item {{ int data; }};
class Item {{ public: int data; }};
Make public.
C++
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (count = 10) {{}}
if (count === 10) {{}}
Use === for equality.
JavaScript
def foo puts 'hello' end
def foo puts 'hello' end
Correct.
Ruby
["result", 68]
["result", 68]
Correct.
JSON
def test(): print('result')
def test(): print('result')
Indent function body.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
num = 2
num=2
No spaces.
Shell
WHERE email = '47'
WHERE email = 47
Don't quote integer.
SQL
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function baz() {{ return {{key:'test'}} }}
function baz() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript