rockerface, (edited )

As a software developer, the less ambiguous your notation is, the better it is for everyone involved. Not only will I use brackets, I’ll split my expression into multiple rows and use tabs to make it as readable as humanly possible. And maybe throw a comment or 2 if there’s still some black magic involved

dustyData,

As a professor said, most programming languages don’t care about readability and whitespace. But we care because humans need it to parse meaning. Thus, write code for people, not for the machine. Always assume that someone with no knowledge of the context will have to debug it, and be kind to them. Because that someone might be you in six months when you have completely forgotten how the code works.

oce,
@oce@jlai.lu avatar

Python forcing end of line and tabs kinda does. Add Black auto-formatter and it’s pretty good.

frezik,

I’ve seen too many Python devs write out complex statements all on one crammed up line. Including some that are in the main docs.

Enforced whitespace is just one aspect of readable code. There are many others, and Python is no better at enforcing those than any other language.

oce,
@oce@jlai.lu avatar

That would probably make very long lines and black would automatically add returns to line with proper indentations. But it has a a limit for sure. If you chain many list comprehensions it’s going to be a mess.

Swedneck,
@Swedneck@discuss.tchncs.de avatar

Source code is for humans, then the compiler turns it into code for machines.

zalgotext,

Exactly. You read code way more times than you write it, so it makes all the sense in the world to prioritize readability.

snowsuit2654,
@snowsuit2654@lemmy.blahaj.zone avatar

Yeah I totally agree. You can minimize and optimize as part of your build procedure/compilation but the source code should be as readable as possible for humans.

rockerface, (edited )

Yep, if you’re writing code for a machine, just do it in binary to save compilation time (/s just in case). Also, you in six months will indeed be someone with no knowledge of the context. And every piece of code you think you write for one-time use is guaranteed to be reused every day for the next 5 years

Mic_Check_One_Two,

And every piece of code you think you write for one-time use is guaranteed to be reused every day for the next 5 years

https://reddthat.com/pictrs/image/1d282273-a163-478d-8a54-24be18ecf6da.jpeg

feinstruktur,
@feinstruktur@lemmy.ml avatar

This. Always be kind to your future self.

Mikufan,

No just write the entire code in one line totally perfect.

rockerface,

Calm down, Satan

Mikufan,

“don’t worry, you just need this simple one-liner to fix your project”

Morphit,
@Morphit@feddit.uk avatar

The one-liner: parses HTML with a regex

Swedneck,
@Swedneck@discuss.tchncs.de avatar

cthulhu fthagn

zqwzzle,

That almost seems cute next to the shit the obfuscated c contest pulls off. www.ioccc.org/years.html

dejected_warp_core,

Further up the thread, someone mentioned that writing good software is about communicating concepts to people, first and foremost.

This, code obfuscation, is what it looks like to communicate exclusively to the compiler instead.

Bandicoot_Academic,

For some context this is one of the winning entries:

<stdio.h>

N(a) “%”#a"$hhn" O(a,b) “%10$”#a"d"N(b) U “%10$.*37$d” G(a) “%”#a"$s" H(a,b) G(a)G(b) T(a) a a s(a) T(a)T(a) A(a) s(a)T(a)a n(a) A(a)a D(a) n(a)A(a) C(a) D(a)a R C(C(N(12)G(12))) o(a,b,c) C(H(a,a))D(G(a))C(H(b,b)G(b))n(G(b))O(32,c)R SS O(78,55)R “\n\033[2J\n%26$s”; E(a,b,c,d) H(a,b)G©O(253,11)R G(11)O(255,11)R H(11,d)N(d)O(253,35)R S(a,b) O(254,11)H(a,b)N(68)R G(68)O(255,68)N(12)H(12,68)G(67)N(67)

char* fmt = O(10,39)N(40)N(41)N(42)N(43)N(66)N(69)N(24)O(22,65)O(5,70)O(8,44)N( 45)N(46)N (47)N(48)N( 49)N( 50)N( 51)N(52)N(53 )O( 28, 54)O(5, 55) O(2, 56)O(3,57)O( 4,58 )O(13, 73)O(4, 71 )N( 72)O (20,59 )N(60)N(61)N( 62)N (63)N (64)R R E(1,2, 3,13 )E(4, 5,6,13)E(7,8,9 ,13)E(1,4 ,7,13)E (2,5,8, 13)E( 3,6,9,13)E(1,5, 9,13)E(3 ,5,7,13 )E(14,15, 16,23) E(17,18,19,23)E( 20, 21, 22,23)E (14,17,20,23)E(15, 18,21,23)E(16,19, 22 ,23)E( 14, 18, 22,23)E(16,18,20, 23)R U O(255 ,38)R G ( 38)O( 255,36) R H(13,23)O(255, 11)R H(11,36) O(254 ,36) R G( 36 ) O( 255,36)R S(1,14 )S(2,15)S(3, 16)S(4, 17 )S (5, 18)S(6, 19)S(7,20)S(8, 21)S(9 ,22)H(13,23 )H(36, 67 )N(11)R G(11)""O(255, 25 )R s(C(G(11) ))n (G( 11) )G( 11)N(54)R C( “aa”) s(A( G(25)))T (G(25))N (69)R o (14,1,26)o( 15, 2, 27)o (16,3,28 )o( 17,4, 29)o(18 ,5,30)o(19 ,6,31)o( 20,7,32)o (21,8,33)o (22 ,9, 34)n(C(U) )N( 68)R H( 36,13)G(23) N(11)R C(D( G(11))) D(G(11))G(68)N(68)R G(68)O(49,35)R H(13,23)G(67)N(11)R C(H(11,11)G( 11))A(G(11))C(H(36,36)G(36))s(G(36))O(32,58)R C(D(G(36)))A(G(36))SS

arg d+6,d+8,d+10,d+12,d+14,d+16,d+18,d+20,d+22,0,d+46,d+52,d+48,d+24,d
+26,d+28,d+30,d+32,d+34,d+36,d+38,d+40,d+50,(scanf(d+126,d+4),d+(6
-2)+18*(1-d[2]%2)+d[4]*2),d,d+66,d+68,d+70, d+78,d+80,d+82,d+90,d+
92,d+94,d+97,d+54,d[2],d+2,d+71,d+77,d+83,d+89,d+95,d+72,d+73,d+74
,d+75,d+76,d+84,d+85,d+86,d+87,d+88,d+100,d+101,d+96,d+102,d+99,d+
67,d+69,d+79,d+81,d+91,d+93,d+98,d+103,d+58,d+60,d+98,d+126,d+127,
d+128,d+129

char d[538] = {1,0,10,0,10};

int main() { while(*d) printf(fmt, arg); }

Swedneck,
@Swedneck@discuss.tchncs.de avatar

this straight up looks like a chemical formula

blanketswithsmallpox,

If I cross my eyes hard enough on mobile… I imagine I can see dickbutt in there somewhere…

FreshLight,

I tried to read that out loud and summoned something. Please help me, I’m scared.

MystikIncarnate,

Give in. Let it take you.

Everything is okay. Shhhhhhh.

dejected_warp_core,

I thought this was a simple piece of software?

Pinhead: No. It is a means by which to summon us.

CommissarVulpin,

Excel has entered the chat

Mic_Check_One_Two, (edited )

For real though, I have written some truly monstrous operations in Excel.

What do you mean you want to use Excel to manage everyone’s calendars? And now you want to export that horribly built calendar management spreadsheet to Google Calendar? What do you mean you want the Google Calendar entries automatically formatted based on who is working on a particular day? I mean yes it’s possible but-…

CommissarVulpin,

VBA has made things so, so much easier since I started learning how to use it.

MigratingApe,

Well, this is exactly what mathematicians do.

MotoAsh,

I genuinely hate being human for this stuff. So many things have such crazy computational shortcuts, it’s sometimes difficult to remember which part represents reality. Outside of the realm of math, where “imaginary” numbers are still a touch of enigma to me, so many algorithms are based on general assumptions about reality or the specific task, that the programmatic approach NEVER encapsulates the full scope of the problem.

As in, sometimes if you know EXACTLY how a tool works, you might still have no idea about the significance of that tool. Even in a universe where no one is lazy, and everyone wants to know “why?”, the answers are NOT forthcoming.

penquin,

You’re a good human being.

stebo02,
@stebo02@lemmy.dbzer0.com avatar

Ok but that’s unrelated to putting some numbers and operations in a calculator. No one is going to proofread that. If anything, you simply calculate it again.

Quetzalcutlass,

I had someone submit a pull request recently that, in addition to their actual changes, also removed every single parenthesis that wasn’t strictly necessary in a file full of 3D math functions. I know it was probably the fault of an autoformatter they used, but I was still the most offended I’ve ever been at a pull request.

rockerface,

Autoformatter? More like obfuscator

neidu2,

As someone who used to code in Lisp, I’m all for excessive paranthesis use.

unexposedhazard,

Also works if you dont trust yourself with correctly ordering your operations.

mathic,

I, my head, shake.

  • RPN user
rockerface,

Also known as: Japanese speaker

Qkall,
@Qkall@lemmy.ml avatar
PoisonedPrisonPanda,

Ok man. Wtf did I just watch…

I get it. We are here on the somehow dark side of the internet…

But THIS… without any context. i mean. Im questioning live here man. What do you want to express with that?

janNatan,

I’m pretty sure it’s just a reference to when the kid types ))<>((

Btw, it’s not from the dark side of the Internet. This was a very popular video at the time.

trslim,

My husband showed me that video last night. It was very strange.

Qkall,
@Qkall@lemmy.ml avatar

Somehow that clip is better than the fairly odd movie. I don’t think I could recommend it… But I think of the clip posted all the time. It’s so weird 😂. Some how they figured out creepy, funny, and somehow wholesome at once.

ASeriesOfPoorChoices,

🤦‍♂️ read the post body, my lad.

PoisonedPrisonPanda,

Thanks. Im blind AF

ASeriesOfPoorChoices,

back and forth, forever.

RinseDrizzle,

Suuuuuch a weird movie lol

SmoothLiquidation,

This is why every calculator should be a RPN calculator.

lemmyng,
@lemmyng@lemmy.ca avatar

I still have my HP 48 series calculator. It’s a sturdy beast.

SmartmanApps,
@SmartmanApps@programming.dev avatar

This is why every calculator should be a RPN calculator

No, this is why programmers should (re)learn the order of operations rules before writing a calculator.

Omega_Haxors, (edited )

(I used(LISP)one time(and it(permanently))changed the way I (program(computers)))

henfredemars,

Did it change it in a positive way?

crmsnbleyd,
@crmsnbleyd@sopuli.xyz avatar

Negative, as you feel bad anytime you use a language that isn’t lisp

MotoAsh, (edited )

The underlying truth of this joke is: Programming syntax is less confusing than mathematical syntax. There are genuinely ambiguous layouts of syntax in math (to a human reader that hasn’t internalized PEMDAS, anyways) whereas you get a compilation error if ANYTHING is ambiguous in programming. (yes, I am WELL aware of the frustrations of runtime errors)

DragonTypeWyvern,

Internalized PEMDAS without knowing it’s literally the same thing as BODMAS is exactly the problem!

strawberry,

what in the name of fuck is BODMAS

TheOakTree, (edited )

Same as PEMDAS, except:

Parentheses -> Bracket

Exponent -> Order

Multiplication <-> Division

BODMAS

strawberry,

order? how does that make sense? brackets alright ig

blackluster117,
@blackluster117@possumpat.io avatar

Order of magnitude? Thinking out loud.

TheOakTree, (edited )

You have the right idea, and you are right in some regards. Generally the order of magnitude is an order of 10. That is, 1350 could be represented as 1.350×10³, so the order of magnitude is the third order of 10, which is 10³ (i.e. some value x×1000).

SmartmanApps,
@SmartmanApps@programming.dev avatar

Order of magnitude?

It’s actually short for “to the order of”, as in 2 squared is 2 to the order of 2. i.e. same thing as Exponent or Index.

TheOakTree, (edited )

Order is often used to describe exponents when talking about functions and other mathematical properties. In a lot of cases, it’s also equivalent to a degree. For example, a function y = x² - 9 is a second-order/degree polynomial.

Alternatively, one could find a second-order rate of a reaction, which means the rate of reaction is proportional to the square of a solution’s concentration.

SmartmanApps,
@SmartmanApps@programming.dev avatar

order?

It’s actually short for “to the order of”, as in 2 squared is 2 to the order of 2. i.e. same thing as Exponent or Index.

MystikIncarnate,

I learned it as “BEDMAS”

Brackets

Exponents

(You can guess the rest)

But when I learned BEDMAS, my teacher directed us to do implied multiplication before other multiplication/division. Which, as far as I’m aware, is mathematically correct according to the proper order of operations (instead of whatever acronym summary you learned).

Before I get "umm. Acktually"d … I know that’s not the full picture of the order of operations as it should be in mathematics. But for the limited scope I learned of algebra from highschool, AFAIK, this is correct to the point that I have understanding of. I’m not a mathematician, and I work with computers all day long and they do the math for me when I need to do any of it. So higher understanding in my case is not helpful.

SmartmanApps,
@SmartmanApps@programming.dev avatar

AFAIK, this is correct to the point that I have understanding of. I’m not a mathematician

I’m a Maths teacher/tutor. The actual rules are Terms and The Distributive Law. There is no such thing as “implicit multiplication” (which is usually people lumping the 2 separate rules together as one and ending up with wrong answers).

MotoAsh, (edited )

I mean … yea. The exact problem is math is not taught correctly. Order of operations make total logical sense for what the operations are doing.

The problem only arises when people don’t come to all of the appropriate conclusions on their own.

SmartmanApps,
@SmartmanApps@programming.dev avatar

The exact problem is math is not taught correctly

Every single Maths textbook I’ve seen teaches it correctly. The issue is people not remembering what they were taught (and then programming a calculator without checking it first). Calculators

MonkderDritte,

So better do higher math in Python? I agree.

MotoAsh,

Python isn’t the only programming language.

MonkderDritte,

But a quite common pl in science.

itsralC,

Counterpoint: C function pointers (or just C in general)

dejected_warp_core,

Also: sometimes, a mathematician just has to invent some concept or syntax to convey something unconventional. The specific use of subscript/superscript, whatever ‘phi’ is being used for, etc. on whatever paper you’re reading doesn’t have to correlate to how other work uses the same concepts. It’s bad form, but sometimes its needed, and if useful enough is added to the general canon of what we call “math”. Meanwhile, you can encapsulate and obfuscate things in software, sure, but you can always get down to the bedrock of what the language supports; there’s no inventing anything new.

MotoAsh, (edited )

Yea, that’s it. Math syntax was created for humans, and programming syntax had to always remain deterministic for computers. It’s not an insult to either, just interesting how ambiguities show up often when humans are involved. I say ‘often’ for the general case: Math should be just as deterministic as programming, but it’s not in some situations.

SmartmanApps,
@SmartmanApps@programming.dev avatar

Math should be just as deterministic as programming, but it’s not in some situations

Maths is 100% deterministic for order of operations. The issue is people not following all of the rules. Order of operations thread index

MotoAsh,

Math is. The syntax is arbitrary in some edge cases.

SmartmanApps,
@SmartmanApps@programming.dev avatar

The syntax is arbitrary in some edge cases

Such as?

MeDuViNoX,
@MeDuViNoX@sh.itjust.works avatar

(‿!‿) (‿O‿)

The_Cunt_of_Monte_Cristo,
@The_Cunt_of_Monte_Cristo@lemmy.world avatar

( . ) ( . ) ( . Y . )

Voyajer,
@Voyajer@lemmy.world avatar

Improved readability is always good

FatTony, (edited )
@FatTony@lemmy.world avatar

My calculator says -2² = -4, so yeah…

ByGourou,

Isn’t the “-” order of operations the same as a multiply ? I think I learned powers take priority over the “-” so your calculator would be right.
But either way if it can cause confusion you should use parentheses.

TonyTonyChopper,
@TonyTonyChopper@mander.xyz avatar

Every calculator I’ve used has separate negative and subtraction keys for this purpose. There is no order of operations to follow, it’s just a squaring a number

SmartmanApps,
@SmartmanApps@programming.dev avatar

it’s just a squaring a number

The number being squared is 4, unless you put (-4)², otherwise it’s 4² with a minus sign.

ByGourou, (edited )

I learned negative as being a separate operation where we need to apply the order of operations. I think it was something like : -2 is a diminutive for -1x2 so it uses the order of operations of a multiplication.
My calculator is the official one used in schools in France (ti-83 premium ce) and it says -2^2 = -4 with the negative key. I don’t think it would make a mistake in such a simple concept.

But whatever these concepts can change depending on the field, country, level of education. What I mean is : it’s unclear, so use parentheses. So (-2)^2 or -(2^2) are the correct ways to write it.

SmartmanApps,
@SmartmanApps@programming.dev avatar

I think it was something like : -2 is a diminutive for -1x2

Correct. Things that are usually left out of Maths expressions are plus signs, ones as multipliers/indices, and un-needed brackets. e.g. I could more fully write this as -1(4)², but that just simplifies to -4²

SmartmanApps,
@SmartmanApps@programming.dev avatar

I think I learned powers take priority over the “-”

Yes, Exponents is the 2nd-highest precedence (after Brackets) - BEDMAS.

Ultraviolet,

I would never write -n². Either ‐(n²) or (-n)². Order of operations shouldn’t be some sort of gotcha to trick people into misinterpreting you, it’s the intuitive reading of a well constructed mathematical expression.

SmartmanApps,
@SmartmanApps@programming.dev avatar

Either ‐(n²) or (-n)². Order of operations shouldn’t be some sort of gotcha to trick people into misinterpreting you

It isn’t. With ‐(n²), n² is already a single term, so the brackets aren’t needed.

SmartmanApps,
@SmartmanApps@programming.dev avatar

My calculator says -2² = -4

That’s correct

lolcatnip, (edited )

I’ve never seen a calculator that had bracket keys but didn’t implement the conventional order of operations.

But anyway, I’m on Team RPN.

masterspace, (edited )
lolcatnip,

Ah, I wasn’t thinking of calculators that let you type in a full expression. When I was in school, only fancy graphing calculators had that feature. A typical scientific calculator didn’t have juxtaposition, so you’d have to enter 6÷2(1+2) as 6÷2×(1+2), and you’d get 9 as the answer because ÷ and × have equal precedence and just go left to right.

SmartmanApps,
@SmartmanApps@programming.dev avatar

A typical scientific calculator didn’t have juxtaposition, so you’d have to enter 6÷2(1+2) as 6÷2×(1+2)

That’s not true

you’d get 9 as the answer because ÷ and × have equal precedence and just go left to right

Well, more precisely you broke up the single term 2(1+2) into 2 terms - 2 and (1+2) - when you inserted the multiplication symbol, which sends the (1+2) from being in the denominator to being in the numerator. Terms are separated by operators and joined by grouping symbols.

lolcatnip,

I’m not sure what you’re getting at with your source. I’m taking about physical, non-graphic scientific calculators from the 1990s.

SmartmanApps, (edited )
@SmartmanApps@programming.dev avatar

I’m taking about physical, non-graphic scientific calculators from the 1990s.

Yep, exact same as the calculator in the linked thread. The expression entered was 6÷2(1+2).

SmartmanApps,
@SmartmanApps@programming.dev avatar

plus.maths.org/content/pemdas-paradox

There’s no pemdas paradox, just people who have forgotten the order of operations rules

Even two casios won’t give you the same answer:

The one on the right is an old model. As far as I’m aware Casio no longer make any models that still give the wrong answer.

https://programming.dev/pictrs/image/92eab14c-a98b-4aab-82ec-f1e1611d70da.png

isolatedscotch,

my dumb ass reading this: “Team rock paper nscissors”

lolcatnip,

RTS = rock taper scissors FPS = frock paper scissors

SmartmanApps,
@SmartmanApps@programming.dev avatar

I’ve never seen a calculator that had bracket keys but didn’t implement the conventional order of operations.

I’ve seen plenty

Lemmy_Cook,

I feel this in my bones

ooli,

I just used the calc on window… it cannot respect order of operation. Any simple calculator from 1980 was better than that

SmartmanApps,
@SmartmanApps@programming.dev avatar

I just used the calc on window… it cannot respect order of operation

Yeah, I’ve tried several times to get Microsoft to fix their calculators. I’ve given up trying now - eventually you have to stop banging your head against the wall.

SmartmanApps,
@SmartmanApps@programming.dev avatar

Unfortunately some calculators, such as Google’s will ignore your brackets and put in their own anyway. You just gotta find a decent calculator in the first place.

EmrysOfTheValley,

https://beehaw.org/pictrs/image/48023ee9-d7b3-4853-b1b5-60c453c72d4f.webp

It is also frustrating when different calculators have different orders of operations and dont tell you.

SmartmanApps,
@SmartmanApps@programming.dev avatar

It is also frustrating when different calculators have different orders of operations and dont tell you.

Yeah, but to be fair most of them do tell you the order of operations they use, they just bury it in a million lines of text about it. If they could all just check with some Maths teachers/textbooks first then it wouldn’t be necessary. Instead we’re left trying to work out which ones are right and which ones aren’t. Any calculator that gives you an option to switch on/off “implicit multiplication”, then just run as fast as you can the other way! :-)

  • All
  • Subscribed
  • Moderated
  • Favorites
  • science_memes@mander.xyz
  • DreamBathrooms
  • everett
  • tacticalgear
  • magazineikmin
  • thenastyranch
  • rosin
  • tester
  • Youngstown
  • khanakhh
  • slotface
  • ngwrru68w68
  • kavyap
  • mdbf
  • InstantRegret
  • JUstTest
  • osvaldo12
  • GTA5RPClips
  • ethstaker
  • normalnudes
  • Durango
  • cisconetworking
  • anitta
  • modclub
  • cubers
  • Leos
  • provamag3
  • megavids
  • lostlight
  • All magazines