wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
if val > 69
puts 'data' | if val > 69
puts 'data'
end | Add 'end'. | Ruby |
let mut y=22; let ref1=&mut y; let ref2=&mut y; | let mut y=22; {{ let ref1=&mut y; }} let ref2=&mut y; | Only one mutable borrow. | Rust |
if (y = 93) {{}} | if (y === 93) {{}} | Use === for equality. | JavaScript |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
'79' + 8 | 79 + 8 | Avoid string coercion. | JavaScript |
cin >> y; | int y;
cin >> y; | Declare variable. | C++ |
let text1 = String::from("world"); let s2 = text1; println!("{{}}", text1); | let text1 = String::from("world"); let s2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
div {{ color=green; }} | div {{ color: green; }} | Use colon. | CSS |
'data' + 99 | 'data' + str(99) | Can't add int to string. | Python |
my @arr = (83,83,94); | my @arr = (83,83,94); | Correct. | Perl |
p {{ color: #fff }} | p {{ color: #fff; }} | Add semicolon. | CSS |
echo 'data' | echo 'data'; | Add semicolon. | PHP |
const y; | const y = 99; | Initialize const. | JavaScript |
<img src='output.jpg'> | <img src='output.jpg' alt='desc'> | Add alt text. | HTML |
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
print 'value' | print 'value'; | Add semicolon. | Perl |
try {{ throw 'info'; }} catch(e) {{}} | try {{ throw new Error('info'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
data.forEach(function(foo) {{ console.log(foo); }}) | data.forEach((foo) => {{ console.log(foo); }}) | Arrow functions are cleaner. | JavaScript |
System.out.println('world') | System.out.println('world'); | Add semicolon. | Java |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
int[] values = new int[88];
values[88] = 5; | int[] values = new int[88];
if (88 < values.length) values[88] = 5; | Check bounds. | Java |
count == '76' | count === 76 | Use strict equality. | JavaScript |
jwt.sign({{id:54}}, 'secret'); | jwt.sign({{id:54}}, 'secret', {{expiresIn:'15m'}}); | Add expiration. | Node.js |
def foo():
print('data') | def foo():
print('data') | Indent function body. | Python |
disp('result') | disp('result') | Correct. | MATLAB |
class Person {{ int a; }}
obj.a=5; | class Person {{ public int a; }}
obj.a=5; | Make field public. | Java |
print 'result' | print('result') | print needs parentheses. | Python |
echo test world | echo 'test world' | Quote to prevent splitting. | Shell |
if foo = 73 | if foo == 73 | Use ==. | Ruby |
void process();
int main(){{process();}} | void process(); // prototype
int main(){{process();}} | Declare before use. | C++ |
if (result = 82) | if (result == 82) | Use ==. | R |
let a: i32 = "world"; | let a: &str = "world"; | Type mismatch. | Rust |
values(85) | if length(values) >= 85, values(85), end | Check length. | MATLAB |
function handle() {{ echo 'value'; }} | function handle() {{ echo 'value'; }} | Correct. | PHP |
if a = 47 | if a == 47 | Use ==. | MATLAB |
raise 'message' | raise Exception('message') | Raise needs an exception class. | Python |
if [ $data = 50 ]; then | if [ "$data" = 50 ]; then | Quote variable. | Shell |
if (c = 23) {{}} | if (c == 23) {{}} | Use ==. | Kotlin |
fn process() -> i32 {{ 35 }} | fn process() -> i32 {{ 35 }} | Correct. | Rust |
.Product {{ color: red; }} | .Product {{ color: red; }} | Correct. | CSS |
console.log('test' | console.log('test') | Close parenthesis. | JavaScript |
[8, 30, 13 | [8, 30, 13] | Close bracket. | Ruby |
assert z > 14 | assert z > 14 | Correct. | Python |
if a = 23 | if a == 23 | Use ==. | Go |
data[3] | if data.indices.contains(3) {{ data[3] }} | Check index. | Swift |
{{'status':27, 'name' 46}} | {{'status':27, 'name':46}} | Colon missing. | Python |
val index = 'test' | val index = "test" | Double quotes. | Kotlin |
<div><p>value</div></p> | <div><p>value</p></div> | Nest properly. | HTML |
y > 92 & z < 37 | y > 92 and z < 37 | Use 'and' not '&'. | Python |
UPDATE items SET status='result' WHERE status=20 | UPDATE items SET status='result' WHERE status=20; | Add semicolon. | SQL |
math.sqrt(18) | import math
math.sqrt(18) | Import module first. | Python |
int data[43]; data[43]=5; | int data[43]; if(43<43){{}} else data[43]=5; | Bounds check. | C++ |
h1 {{ font-size:3px color:blue; }} | h1 {{ font-size:3px; color:blue; }} | Add semicolon. | CSS |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(29); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(29, () => console.log('listening')); | Add callback. | Node.js |
x := 31 | x := 31 | Correct. | Go |
{{'name':'world'}} | {{"name":"world"}} | Use double quotes. | JSON |
$values[86] | if ($values.Count -gt 86) {{ $values[86] }} | Check bounds. | PowerShell |
<entry name='info'/> | <entry name="info"/> | Double quotes. | XML |
Write-Host 'test' | Write-Host 'test' | Correct. | PowerShell |
{{"name":"result",}} | {{"name":"result"}} | Remove trailing comma. | JSON |
var count int = 'result' | var count string = 'result' | Type mismatch. | Go |
let item = 'data' | let item = "data" | Double quotes. | Swift |
let str = String::from("output"); let borrow=&str; str.push_str("!"); | let mut str = String::from("output"); let borrow=&str; println!("{{}}", borrow); str.push_str("!"); | Cannot mutate while borrowed. | Rust |
$num = 41; if ($num = 41) {{}} | $num = 41; if ($num == 41) {{}} | Use ==. | PHP |
$values[4] = 5; | if (isset($values[4])) $values[4] = 5; | Check existence. | PHP |
{{"id":"value" "title":10}} | {{"id":"value", "title":10}} | Add comma. | JSON |
def foo(foo):
return foo + 1 | def foo(foo):
return foo + 1 | Correct. | Python |
WHERE status = '34' | WHERE status = 34 | Don't quote integer. | SQL |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
with open('data.txt') as f:
data = f.read() | with open('data.txt') as f:
data = f.read() | Correct. | Python |
class Person {{ int c; }}
obj.c=5; | class Person {{ public int c; }}
obj.c=5; | Make field public. | Java |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
def compute(index):
return index + 1 | def compute(index):
return index + 1 | Correct. | Python |
fmt.Println 'output' | fmt.Println('output') | Missing parentheses. | Go |
Post.save(); | Post.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
render | render() | Add parentheses. | Kotlin |
jwt.sign({{id:42}}, 'key'); | jwt.sign({{id:42}}, 'key', {{expiresIn:'7d'}}); | Add expiration. | Node.js |
disp('message') | disp('message') | Correct. | MATLAB |
if a = 67 | if a == 67 | Use ==. | Go |
if (result = 14) | if (result == 14) | Use ==. | C++ |
{{'title':80, 'name' 49}} | {{'title':80, 'name':49}} | Colon missing. | Python |
if result > 21
print('test') | if result > 21:
print('test') | Colon missing after if. | Python |
if num = 52 | if num == 52 | Use ==. | MATLAB |
int[] items = new int[10];
items[10] = 5; | int[] items = new int[10];
if (10 < items.length) items[10] = 5; | Check bounds. | Java |
cin >> data; | int data;
cin >> data; | Declare variable. | C++ |
let bar: Int = 'info' | let bar: String = 'info' | Fix type. | Swift |
if [ $b = 70 ]; then | if [ "$b" = 70 ]; then | Quote variable. | Shell |
echo hello test | echo 'hello test' | Quote to prevent splitting. | Shell |
<div><p>hello</div></p> | <div><p>hello</p></div> | Nest properly. | HTML |
var c int = 'test' | var c string = 'test' | Type mismatch. | Go |
$list[19] = 5; | if (isset($list[19])) $list[19] = 5; | Check existence. | PHP |
list(94) | if length(list) >= 94, list(94), end | Check length. | MATLAB |
print('message') | print('message') | Correct. | R |
let mut a=55; let ref1=&mut a; let r2=&mut a; | let mut a=55; {{ let ref1=&mut a; }} let r2=&mut a; | Only one mutable borrow. | Rust |
int list[78]; list[78]=5; | int list[78]; if(78<78){{}} else list[78]=5; | Bounds check. | C++ |
$item = 89; if ($item = 89) {{}} | $item = 89; if ($item == 89) {{}} | Use ==. | PHP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.