101
58
35
u/valschermjager Aug 27 '21
needs no comments. naming of variables and functions are self-documenting. obviously.
58
u/ThatDudeBesideYou Aug 28 '21 edited Aug 28 '21
Idk if people are joking around when they say there's not a lot wrong with it, but this is actually terrible code. Not for the use of Japanese, but from the code itself. Since this sub is about explaining why code is bad, I'll give it a shot. I probably will miss some stuff.
If num1 or num2< 0 will almost always return true no matter the numbers. (if num1 is 0 and num2 is less than 0 that would be the only false. Negative num1 will return true).
Setting the 正 to True and then just returning not True is unnecessary.
That addition function will sometimes return a boolean instead of a number, which is unexpected behaviour for an addition function.
The triple not is silly but w/e.
For false, why use 雨 (rain)?If you're trying to replace true and false with characters, do it at the top of your code and perhaps use the translation consistently.
14
Aug 28 '21
My guess about the 雨 is that it's one of those real life examples that teachers use teach boolean algebra (like "is raining" or "not weekend" = not party, or something like that)
4
3
u/Roflkopt3r Aug 28 '21
I'm not sure if this is somehow makes sense in python, but the function 数を計算する(数1, 数2) seems either completely superfluous or should be somewhere else rather than in the middle of another function.
1
u/Matalya1 Sep 04 '21
if num1 or num2 < 0: #codeis a valid expression, but it's
if (num1) or (num2 < 0):and it uses the concept of truthiness. If
num1(Assuming it's storing an integer) is greater than zero, it'll returnTrueregardless of the value ofnum2XD Doingif numis the same as doingif num>0, other examples areif len(array) > 0andif len(string) > 0.2
u/ThatDudeBesideYou Sep 04 '21
I mentioned it in the comment, but "if num" isnt the same as "if number>0". It's equivalent to "if !!num". So only if num is 0, (or None or undefined) it will return false, all other values will return true.
19
u/mpcs127 Aug 28 '21
if not not not 雨 what the fuck
8
u/h7x4 Aug 28 '21 edited Aug 28 '21
Weather report for today says it's not supposed to not pour down't ¯_(ツ)_/¯
21
18
u/awatt23 Aug 27 '21
This honestly looks like a fun way to learn two things at once. Probably someone learning their first bit of python and practicing their Japanese simultaneously.
5
u/Roflkopt3r Aug 28 '21
People here say they could roughly figure out what's going on even without the text, so this could also be used the other way around: Learn a new language and coding through "code stories".
Kind of an ultra specific market by aiming at people who try to learn programming and a language at the same time, but honestly sounds like a format with potential.
8
u/RedEyesBigSmile Aug 28 '21
line 7 and 17 really want to make me commit seppuku.
But tbh I like the color scheme
8
4
4
4
4
Aug 27 '21
Why so many not's?
10
u/GMaestrolo Aug 28 '21
Well the first
notcoerces it to Boolean, but then it's the wrong Boolean value, so the secondnotconverts the Boolean back to the correct value, then obviously they need to check the opposite of that, so they slapped anoton that bad boy.
2
2
2
u/thanatica Sep 01 '21
It's probably just to quickly knock together something funny. For that, it's alright code.
The only thing that gets on me nerves is the if not not not 雨, so is it not not not raining, or is it? (雨 means rain)
I am now itching to start using non-ASCII variables, but I fear it might anger my coworkers, because they are "special" characters and that "should not work". Or something. Maybe I'll give it a go, for funsies.
1
Sep 05 '21
do it. i kinda wanna make a language that's just like all foreign characters like emojis or whatever
1
2
u/propostor Aug 27 '21
Doesn't actually look that bad, all things considered.
I don't know Japanese but could still follow what the code was doing
2
1
u/xSilverMC Aug 27 '21
Other than the weird boolean shenanigans i don't see anything really wrong with it, idk why the counter is in katakana though
1
1
1
1
1
u/Nonsensicallity Aug 28 '21
“not 正” is a lot less ambiguous than guessing whether or not the Boolean value is capitalized when you switch gears from one language to another.
1
u/yvt Aug 28 '21
Aside from the fundamentally wrong part, actually we do something like this depending on problem domains and whom we are writing for. Non-Latin identifiers are indeed harder to type, but attempting to translate technical terms with no well-known English translations is likely to create more problems.
1
1
1
u/incoralium Aug 28 '21
It is bad.
Not Not Not
No += increment ...
Other language or ok if not a shared dev (look at the path it's literally a playground)
1
u/strindhaug Aug 28 '21
So this code will ask your name, greet you with that name, say Sum=False and then print 10 repeats of a dot and an emoji?
1
1
1
u/Dmon1Unlimited Aug 28 '21
How does coding with different languages work?
If you want to reference a library with an English name that may not have a name in your language?
1
1
u/WisconsinBadger414 Aug 28 '21
I would have just returned the sum in that first else statement to make match the if statement, why assign it to a variable then return that when you can just put a return on the line
1
1
u/BarryFruitman Sep 02 '21
not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not not
1
1
1
0
u/iYashodhan Aug 27 '21 edited Aug 27 '21
I don't understand, this shouldn't work, right? I mean does python interpreter understands foreign language variables and function name? I don't think so, how come?
Edit: I found one stack overflow question: https://stackoverflow.com/questions/53224425/how-can-i-use-japanese-language-characters-in-variable-naming
14
u/WpGgs Aug 27 '21
Python 3 supports unicode identifier. It's allowed to name a user-defined variable, function, class, … with these unicode characters.
9
u/awatt23 Aug 28 '21
I kind of had to appreciate it once, though having a laugh, when working with Chinese devs and I saw the variable
read了to differentiate from the methodread, since the present and past tense are the same in English. He didn't want to putreadedI mean they are the same in Chinese too (no tense) and we can argue linguistics about this variable, but it was something immediately everyone understood and it added clarity.
It was just an absolute pain to switch keyboards mid-word every time I used the variable and I ended up committing a change to
linesorresultor something like that6
u/piman51277 Aug 27 '21
oh god
0
Aug 28 '21
Wait until somebody starts trying to use homoglyphs as variable names 🙄
4
u/TinyBreadBigMouth Aug 28 '21
As recommended by the Unicode Identifier Annex, which Python more-or-less implements straight, 1) identifiers are still limited to letters and numbers, and 2) all identifiers are NFKC-normalized. This eliminates most if not all possible homoglyph issues. For example,
Ⓓifferentwill be normalized toDifferentinternally.-1
9
u/TinyBreadBigMouth Aug 28 '21
I mean does python interpreter understands foreign language variables and function name?
Heck, the Python interpreter doesn't understand English language variables and function names. It doesn't care if you name a variable
apples,apyls,ayhsjkui, orりんご. It's all just text.To clarify, Python does not let you stick emojis or random garbage symbols in there, it still mostly restricts you to letters and numbers, but since 2007 it supports letters and numbers from other languages. Which is perfectly reasonable; I mean, programmers from other countries exist, and there's no reason to prevent people from writing in their native language if they want to.
2
u/Deykun Aug 28 '21
In Poland government own software is often wrote with polish var names, I believe it is one of requirements in the contract, but it looks horrifying to see random polish jestPapiezMartwy when a broken English is a standard naming convention.
1
3
u/Kyidou Aug 28 '21
Why do you think it wouldn't work? Variables and functions are just stored bits of information defined under a name.
1
-1
-1
-1
-2
-3
-3
0
Aug 27 '21
[deleted]
173
u/joonatoona Aug 27 '21
name = input("Please enter your name: ") emoticon = "(°▽°)/ 🙇" print("Hello {}! {}".format(name,emoticon)) def addNumbers(number1, number2): true = True if number1 or number2 < 0: return not true else: sum = number 1 + number2 return sum print("sum =", addNumbers(6, 9)) rain(?) = False counter = 1 if not not not rain: while counter < 11: print(str(counter) + ". 😂😂") counter = counter + 1God trying to format that on mobile sucked, and I probably got some of that wrong anyways.
75
Aug 28 '21
if not not not? WTF is with the triple negative?40
u/ycohui Aug 28 '21
that was the original code had triple not....
33
Aug 28 '21
Yes, but why?
47
u/SoulslikePursuer Aug 28 '21
In the case the computer will forget, you always need to remind it a few times...what a stupid questions you ask mate.............
7
9
7
u/lkmnoppo Aug 28 '21
You can use double negation to convert from truthy-value to boolean, maybe the programmer wanted to do something like that. But you usually do double negation, not triple. Triple negation should have the same effect as single negation also on truthy values.
16
u/mestrearcano Aug 28 '21
Maybe the phrase not not not rain is a common phrase in japanese or some inside joke for those involved.
27
u/dpk84 Aug 28 '21
I think I’m Japanese but I don’t have any idea about the “not not not 雨”. And besides , 数を計算する is not wrong sentence but 足し算をする is better expression for the function which is just add up. So the code might be written by not a Japanese speaker or I’m ignorance.
45
u/Roflkopt3r Aug 28 '21
I think I’m Japanese
But you aren't certain? :D
4
2
u/supersharp Sep 01 '21
Reminds me of that Impractical Jokers bit where they have the guy write an email to a fictional long-time friend, solely to ask him if he's Asian.
3
u/Qildain Aug 28 '21
I'm sure you're not ignorant. Lots of people have strange ways of phrasing things in a language other than their first.
2
u/TheUnlocked Aug 28 '21
Given that the title of the file is "日本語.py," I think you're right that Japanese might not be their usual language.
9
u/G-Force-499 Aug 27 '21
I really don’t understand the purpose of the last bit of code
3
u/dreamin_in_space Aug 28 '21
Probably why it was posted here, other than to flex on English-only speakers :D
4
u/coldnebo Aug 27 '21
not sure about Python, but in Ruby || and “or” have different precedence, so they are not equivalent. work went through a phase a few years ago where everyone thought it was hip to use the words “and” “or” instead of the logical operators not realizing that the words are flow control constructs borrowed from Perl, such as: “file.close or die”. or in Rails: “render and return”
we spend years correcting all the logic errors introduced by those changes.
9
u/TinyBreadBigMouth Aug 28 '21
Python only has
or(logical short-circuiting or) and|(binary or). No wonky precedence stuff.1
u/coldnebo Aug 29 '21
ah, interesting.. I wonder if there are code styles in python that prefer words over symbols? which is more idiomatic in Python?
2
u/TinyBreadBigMouth Aug 29 '21
They do completely different things, so there isn't really any style choice to be had there. In general the only reason to use binary OR is if you're doing bit manipulation. I.e.,
0b00101 | 0b10110 == 0b10111.1
2
u/the_vikm Aug 28 '21
borrowed from Perl,
Weird folks, since Perl has also both (Ruby borrowed the whole concept)
4
u/lumo19 Aug 28 '21
I know a little Japanese and recognized the ame kanji, but didn't want to accept such a non pythonic variable name and assumed I read it wrong.
5
4
u/chunkyasparagus Aug 28 '21
You missed a character in the function name, should be:
数を計算する
Otherwise, awesome work!
3
2
0
Aug 27 '21
[deleted]
13
0
Aug 27 '21
[deleted]
83
1
u/darkdaemon000 Aug 30 '21
You take the help of OCRs? I think most of the images can be converted to text with high accuracy.
0
Aug 30 '21
[deleted]
1
Sep 01 '21
honestly you could post on a programming subreddit, im pretty sure theres lots of people wanting to help you with your work.
595
u/delta-samurai Aug 27 '21
This is the first piece code I've ever seen in another language