There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

onlinepersona , in new preference war just dropped

I used to like the action followed by direct object format, until some time ago when trying to find methods or variables related to a specific object. If the action comes first, scanning for the object without an IDE means first reading unnecessary information about the action. That convinced me to opt for $object-$action in situations where it makes sense.

For example in CSS, I often scan for the element, then the action, so $element-$action makes more sense. BEM kinda follows this. When dealing with the DOM in JS, that makes sense too button.fileDialogOpen(), button.fileDialogSend(), … makes more sense when searching.

Of course one has to use it sensibly and where necessary. If you are writing a code that focuses more on actions than objects, putting the action first makes sense.

A similar thing is definition order.


<span style="font-weight:bold;color:#a71d5d;">def </span><span style="font-weight:bold;color:#323232;">main</span><span style="color:#323232;">(args):
</span><span style="color:#323232;">  result </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#323232;">do_something(args.input)
</span><span style="color:#323232;">  processed </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#323232;">process_result(result)
</span><span style="color:#323232;">  transformed </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#323232;">transform_object(processed)
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">return </span><span style="color:#323232;">transformed.field
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">def </span><span style="font-weight:bold;color:#323232;">do_something</span><span style="color:#323232;">(some_input):
</span><span style="color:#323232;">  </span><span style="color:#0086b3;">...
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">def </span><span style="font-weight:bold;color:#323232;">process_result</span><span style="color:#323232;">(result):
</span><span style="color:#323232;">  </span><span style="color:#0086b3;">...
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">def </span><span style="font-weight:bold;color:#323232;">transform_object</span><span style="color:#323232;">(obj):
</span><span style="color:#323232;">  </span><span style="color:#0086b3;">...
</span>

I find this much easier to follow than if main were defined last, because main is obviously the most important method and everything else is used by it. A flattened dependency tree is how these definitions make sense to me or how I would read them as newbie to a codebase.

Anti Commercial-AI license

gandalf_der_12te OP ,

I agree with you especially on the definition order of functions. I, too, define main() first.

dariusj18 , in new preference war just dropped

Be php, mix and match

gandalf_der_12te OP ,

let the chaos reign

Anticorp , in Saw 37 the software Dev

NP, dude. As someone who learned JavaScript in the dark ages, when IE had to be a consideration for everything you did, writing a JS program now is trivial.

PhlubbaDubba , in Saw 37 the software Dev

“Every time you try to run the pendulum will drop lower until…”

Extremely loud crash as pendulum is rocketed in the ground by all the failed run attempts

victorz , in Saw 37 the software Dev

Learn JavaScript. It’s a pretty good language. 👍

teletext , in Saw 37 the software Dev

Sorry bro, if you think JavaScript is difficult, then you’re just too weak.

Kolanaki , in Saw 37 the software Dev
@Kolanaki@yiffit.net avatar

Ok… He didn’t say it had to be complicated or anything. Just make a magic 8 ball.

kakes , in Saw 37 the software Dev

I think I’d be okay up until you pulled intellisense, at which point I would literally deflate like a balloon.

Mikufan , in Saw 37 the software Dev

Do it in php and say its JavaScript, most people don’t even know that there is a difference.

xmunk ,

$facts

alexdeathway , (edited ) in new preference war just dropped
@alexdeathway@programming.dev avatar

First one are method name, second one are status name.


<span style="color:#323232;">
</span><span style="color:#323232;">def open_file_dialog(self):
</span><span style="color:#323232;">       self.dialog_file_open = True
</span><span style="color:#323232;">       pass
</span><span style="color:#323232;">
</span>

Yoda level preference war.

Croquette ,

I tend to add is to booleans toreally differentiate between a method name and a status.


<span style="color:#323232;">def open_file_dialog(self):
</span><span style="color:#323232;">    self.dialog_file_is_open = True
</span><span style="color:#323232;">    pass
</span>

That way, it’s easier for my dumb brain to spot which is which at a glance.

fourwd ,
@fourwd@programming.dev avatar

In Elixir, we mark statuses by using a question mark at the end of the variable name. Something like this:


<span style="color:#323232;">authorized? = user |> get_something() |> ensure_authorized?()
</span>

I like this better than the is_ prefix

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

does ‘?’ have type definition in elixir or this is generally agreed design pattern?

Faresh ,

If it’s like Lisp, then ? is just part of the symbol and doesn’t have any special syntatic meaning. In different Lisps it’s also convention to end predicate names with a ? or with P (p for predicate)

cytokine0724 ,

jealously weeps in ruby

FMT99 ,

We do this in Ruby all the time, we just prefer methods over variables, usually.


<span style="color:#323232;">def authorized?
</span><span style="color:#323232;">  current_user&.authorized?
</span><span style="color:#323232;">end
</span>
cytokine0724 ,

I’m a principal backend engineer routinely writing Ruby for my day job, so I’m familiar, lol. But you can’t do it for local variables and that just sucks. Definitely a +1 for Elixir.

db0 ,
@db0@lemmy.dbzer0.com avatar

is_dialog_file_open

fite me

TheSlad ,

No fiting. IS always goes at the start of names for booleans you are correct

sus ,

that works for 2 word names eg is_open or is_file, but in this case is_dialog_file_open is structured like a question, while dialog_file_is_open is structured like a statement

red ,

It still works. is_this_thing_some_thingy. Is is just a prefix for if the suffix returns true/false.

Rinox ,

Doesn’t matter, the point is that, if it starts with “is” then you automatically know it’s a boolean.

Yondoza ,

This is the way.

Command statement = an action

Question statement = a status

crispy_kilt ,

Lol mutable state

jarfil , in new preference war just dropped

Both:


<span style="color:#323232;">dialog_error = Dialog_plain.create_modal(error_text)
</span>

Variable and class names go from more general to more particular, functions begin with a verb.

Global functions are either “main”, or start with one of “debug”, “todo”, or “shit”.

somegeek , in Not really sure whether S-expressions or Python indentation-based scoping get more hate...

Python has one of the worst syntaxes out there

cupcakezealot , in new preference war just dropped
@cupcakezealot@lemmy.blahaj.zone avatar

the people who chose the first one…who hurt you?

habl ,

I will

MechanicalJester ,

No one, it just makes sense.

You must be one of those “Throw your mother downstairs, the box of tissues” types.

Yoda sounded normal to you I bet.

loudWaterEnjoyer ,
@loudWaterEnjoyer@lemmy.dbzer0.com avatar

It makes sense until you write 30 methods to manipulate the data layer.

Lifter ,

Fuzzy search solves this pretty good

Swedneck ,
@Swedneck@discuss.tchncs.de avatar

reverse polish notation time

lightnsfw ,

Powershell

Wimopy , in Hot Potato License

Ok, I might be misunderstanding here, but since committing changes is allowed for everyone, doesn’t this mean fixing bugs is something you could do? You’d just be stuck with all the other rights as well until someone else makes a change.

unexposedhazard ,

The main dev made the last commit, so they dont have the right to make another commit, until they arent the last person to make a commit anymore (until someone else has made a commit). This makes sure that there are at least 2 people making commits but hopefully much more.

In other words, making a commit revokes your right to do so until someone else makes a commit.

Cethin ,

Am I just bad at reading? It says the right to make changes is granted to everyone one Earth. That would include the last person to make a commit as well, assuming they’re a citizen of Earth. I’m sure what you’re saying is what it’s supposed to say, but it isn’t actually what it says.

mexicancartel ,

All rights reserved by…, except the right to commit to this repository.

Being a legal license it requires much more rigorous and clear statement

stankmut ,

You can’t just ignore the second part of that sentence which gives the right to make commits to all citizens of earth. That would include the person who wrote the last commit.

mexicancartel ,

Thats why I said it needs to be more rigorous. The license probably meant Everyone in the earth except the last person who commited to it

lugal ,

Are you doxing OOP right now??? How do you know they life on earth?

mexicancartel ,

All rights reserved by…, except the right to commit to this repository.

Being a legal license it requires much more rigorous and clear statement

sxan ,
@sxan@midwest.social avatar

That may be what they meant, but that’s not what it says.

zewm ,
@zewm@lemmy.world avatar

The fact that you have 38 upvotes with such an incorrect statement is mind boggling.

This is how politics works I supposed. Write something that sounds plausible but is completely incorrect, inaccurate or completely fabricated and stupid people applaud and follow.

unexposedhazard , (edited )

Its ok to be unable to read, but dont make that other peoples problem.

github.com/ErikMcClure/…/hot-potato-license

This is copied from V2 but same thing:

All rights reserved by the last person to commit a change to this repository,

No explanation needed

except for the right to commit changes to this repository,

Also no explanation needed

which is hereby granted to all inhabitants of the Milky Way Galaxy for the purpose of committing changes to this repository.

This refers to the previous section meaning everyone can make commits to the repository except for the person excluded by that same section

Zeshade ,

They should’ve said “all other inhabitants” to remove the ambiguity.

brisk ,

A right not being reserved does not mean it is waived, only that it is not exclusive. The last person to commit still has the right to commit, as does everyone else.

FiniteBanjo ,

Yeah, the problem with the proposition is that you have all rights and access to the code regardless of who made the last commit, unless the last person to commit revoked the HPL.

MNByChoice ,

The last person cannot revoke the right to make commits.

I have no idea what that implies about the right to change the license.

Swedneck ,
@Swedneck@discuss.tchncs.de avatar

the fact that there are this many people having different interpretations shows that the license would need waaaaaay clearer wording to hold any sort of water.

this is why i hate licenses like WTFPL and its ilk, just saying “do whatever” cannot possibly be legally viable and thus using anything with such a license is impossible by anyone who cares about copyright law (such as say, companies).

If you want your creations to be free for all to use, just slap a fat CC0 on it.

ArmokGoB , in Hot Potato License
  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • [email protected]
  • lifeLocal
  • goranko
  • All magazines