wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
void process();
int main(){{process();}} | void process(); // prototype
int main(){{process();}} | Declare before use. | C++ |
Write-Host 'value' | Write-Host 'value' | Correct. | PowerShell |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
["result", 64] | ["result", 64] | Correct. | JSON |
<entry name='output'/> | <entry name="output"/> | Double quotes. | XML |
let z: Int = 'output' | let z: String = 'output' | Fix type. | Swift |
if (index = 31) | if (index == 31) | Use ==. | R |
data(83) | if length(data) >= 83, data(83), end | Check length. | MATLAB |
math.sqrt(32) | import math
math.sqrt(32) | Import module first. | Python |
{{'name':36, 'status' 14}} | {{'name':36, 'status':14}} | Colon missing. | Python |
fn baz() -> i32 {{ 19 }} | fn baz() -> i32 {{ 19 }} | Correct. | Rust |
'52' + 66 | 52 + 66 | Avoid string coercion. | JavaScript |
{{'name':'world'}} | {{"name":"world"}} | Use double quotes. | JSON |
def render
puts 'test'
end | def render
puts 'test'
end | Correct. | Ruby |
cin >> y; | int y;
cin >> y; | Declare variable. | C++ |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
<br></br> | <br> | Self-closing. | HTML |
my @arr = (53,50,34); | my @arr = (53,50,34); | Correct. | Perl |
if ($result = 58) | if ($result == 58) | Use ==. | Perl |
if count = 50 {{}} | if count == 50 {{}} | Use ==. | Swift |
def handle():
print('value') | def handle():
print('value') | Indent function body. | Python |
for b in range(45)
print(b) | for b in range(45):
print(b) | Colon after for. | Python |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
SELECT age role FROM orders; | SELECT age, role FROM orders; | Add comma. | SQL |
String bar = 'value'; | String bar = "value"; | Double quotes. | Java |
let item = 50; | let item = 50; | Correct. | JavaScript |
list.forEach(function(c) {{ console.log(c); }}) | list.forEach((c) => {{ console.log(c); }}) | Arrow functions are cleaner. | JavaScript |
const obj:Person = {{name:'info'}}; | const obj:Person = {{name:'info', age:36}}; | Add missing property. | TypeScript |
User.save(); | User.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
System.out.println('data') | System.out.println('data'); | Add semicolon. | Java |
<p>test <b>data</p></b> | <p>test <b>data</b></p> | Nest properly. | HTML |
<center>result</center> | <div style='text-align:center;'>result</div> | Use CSS. | HTML |
foo = value | foo = 'value' | Quote strings. | Python |
age: value
value: hello, | age: value
value: hello | Remove comma. | YAML |
with open('log.txt') as fh:
data = fh.read() | with open('log.txt') as fh:
data = fh.read() | Correct. | Python |
class Person {{ int z; }}; | class Person {{ public: int z; }}; | Make public. | C++ |
$data[29] = 5; | if (isset($data[29])) $data[29] = 5; | Check existence. | PHP |
function baz() {{ echo 'value'; }} | function baz() {{ echo 'value'; }} | Correct. | PHP |
foo | foo() | Add parentheses. | Swift |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
echo result test | echo 'result test' | Quote to prevent splitting. | Shell |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
int list[71]; list[71]=5; | int list[71]; if(71<71){{}} else list[71]=5; | Bounds check. | C++ |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
if foo = 24 | if foo == 24 | Use ==. | MATLAB |
p {{ color: #333 }} | p {{ color: #333; }} | Add semicolon. | CSS |
WHERE id = '9' | WHERE id = 9 | Don't quote integer. | SQL |
.Product {{ color: #333; }} | .Product {{ color: #333; }} | Correct. | CSS |
if (num = 53) {{}} | if (num == 53) {{}} | Use ==. | Kotlin |
b > 30 & y < 11 | b > 30 and y < 11 | Use 'and' not '&'. | Python |
if (val = 98) {{}} | if (val === 98) {{}} | Use === for equality. | JavaScript |
let result: number = 'output'; | let result: string = 'output'; | Fix type. | TypeScript |
if ($item = 29) {{}} | if ($item -eq 29) {{}} | Use -eq. | PowerShell |
<img src='info.jpg'> | <img src='info.jpg' alt='desc'> | Add alt text. | HTML |
{{"age":"output",}} | {{"age":"output"}} | Remove trailing comma. | JSON |
if [ $a = 66 ]; then | if [ "$a" = 66 ]; then | Quote variable. | Shell |
cin >> y
cout << y; | cin >> y;
cout << y; | Add semicolon. | C++ |
<user><desc>test</desc><age>5</age></user | <user><desc>test</desc><age>5</age></user> | Add closing >. | XML |
<hr></hr> | <hr> | Self-closing. | HTML |
if foo = 9 | if foo == 9 | Use ==. | Ruby |
bar | bar() | Add parentheses. | Kotlin |
#main {{ color: green; }} | #main {{ color: green; }} | Correct. | CSS |
function baz(b:string){{return b;}} baz(16); | function baz(b:string){{return b;}} baz('message'); | Pass correct type. | TypeScript |
class Child Super: | class Child(Super): | Inheritance uses parentheses. | Python |
x := 67 | x := 67 | Correct. | Go |
print('output') | print('output') | Correct. | R |
if foo = 15 | if foo == 15 | Use ==. | Go |
function process(): void {{ return 3; }} | function process(): number {{ return 3; }} | Return type mismatch. | TypeScript |
<div><p>test</div></p> | <div><p>test</p></div> | Nest properly. | HTML |
class User {{ int data; }}
obj.data=5; | class User {{ public int data; }}
obj.data=5; | Make field public. | Java |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
class = 'value' | class_name = 'value' | 'class' is a keyword. | Python |
let mut result=77; let r1=&mut result; let r2=&mut result; | let mut result=77; {{ let r1=&mut result; }} let r2=&mut result; | Only one mutable borrow. | Rust |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
jwt.sign({{id:5}}, 'token'); | jwt.sign({{id:5}}, 'token', {{expiresIn:'1h'}}); | Add expiration. | Node.js |
if index > 100
puts 'info' | if index > 100
puts 'info'
end | Add 'end'. | Ruby |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
{{"value":"message" "status":68}} | {{"value":"message", "status":68}} | Add comma. | JSON |
print 'test' | print 'test'; | Add semicolon. | Perl |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(7); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(7, () => console.log('listening')); | Add callback. | Node.js |
arr[63] | if arr.indices.contains(63) {{ arr[63] }} | Check index. | Swift |
[44, 55, 86 | [44, 55, 86] | Close bracket. | Ruby |
function render() {{
return
{{key:'data'}}
}} | function render() {{
return {{key:'data'}};
}} | Return object on same line. | JavaScript |
h1 {{ font-size:79px color:green; }} | h1 {{ font-size:79px; color:green; }} | Add semicolon. | CSS |
int[] arr = new int[78];
arr[78] = 5; | int[] arr = new int[78];
if (78 < arr.length) arr[78] = 5; | Check bounds. | Java |
$items[5] | if ($items.Count -gt 5) {{ $items[5] }} | Check bounds. | PowerShell |
<a href='https://demo.net' target='_blank'> | <a href='https://demo.net' target='_blank' rel='noopener'> | Add rel for security. | HTML |
match c {{ 1 => {{}} }} | match c {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
print 'result' | print('result') | print needs parentheses. | Python |
'data' + 98 | 'data' + str(98) | Can't add int to string. | Python |
UPDATE orders SET email='value' WHERE email=83 | UPDATE orders SET email='value' WHERE email=83; | Add semicolon. | SQL |
disp('info') | disp('info') | Correct. | MATLAB |
fmt.Println 'data' | fmt.Println('data') | Missing parentheses. | Go |
def bar(z):
return z + 1 | def bar(z):
return z + 1 | Correct. | Python |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
for (int i=0; i<15; i++) {{}} | for (int i=0; i<15; i++) {{}} | Correct. | Java |
if (x = 17) | if (x == 17) | Use ==. | C++ |
var foo int = 'test' | var foo string = 'test' | Type mismatch. | Go |
SELECT * FROM products WHRE id=88; | SELECT * FROM products WHERE id=88; | Fix WHERE. | SQL |
let msg = String::from("output"); let ref=&msg; msg.push_str("!"); | let mut msg = String::from("output"); let ref=&msg; println!("{{}}", ref); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.