|
TooMuchAbstraction posted:I do like the order of operations in the ternary operator better, but I hate using "?" and ":" as control flow indicators; keywords are definitely preferable. Isn't it: foo = baz if bar else quux ?
|
# ? Aug 11, 2017 19:00 |
|
|
# ? Jun 7, 2024 23:29 |
|
I kinda like using the trailing "if" in Ruby for raising exceptionscode:
Mezzanine fucked around with this message at 19:08 on Aug 11, 2017 |
# ? Aug 11, 2017 19:06 |
|
Yes, he wants the ternary format of if/then/else which Python doesn't use. I like the ternary format better as well.
|
# ? Aug 11, 2017 19:07 |
|
TooMuchAbstraction posted:I guess Python doesn't allow "foo = if bar then baz else quux" because it doesn't read nicely? I’d guess it can’t be LL(1) parsed but I’m rusty on that
|
# ? Aug 11, 2017 19:10 |
|
leper khan posted:Isn't it: Yes, but ternary operators tend to go: code:
code:
|
# ? Aug 11, 2017 19:10 |
|
also related is python's for...else loop which is such an obvious idea except the issue is that that's not what it actually is if you do not know what python's for...else loop is, try guessing the meaning of this code Python code:
|
# ? Aug 11, 2017 19:14 |
I find the Python version easier to read, because python uses english words rather than ?. If they're straight assignments, it's equivalent to Python code:
Suspicious Dish posted:also related is python's for...else loop which is such an obvious idea except the issue is that that's not what it actually is It's so poorly named, even though I love the construct. It should really be called no break (and in the case of try/except/else/finally, no except). My solution is as follows: every single time I use for/else or while/else, I do this: Python code:
Eela6 fucked around with this message at 19:20 on Aug 11, 2017 |
|
# ? Aug 11, 2017 19:15 |
|
Suspicious Dish posted:also related is python's for...else loop which is such an obvious idea except the issue is that that's not what it actually is things is null?
|
# ? Aug 11, 2017 19:17 |
|
Mezzanine posted:things is null? Close: things is falsy
|
# ? Aug 11, 2017 19:38 |
|
I think python tries to be too cute in situations like this. The equivalent code is something like:code:
EDIT: I know it's a pythonista preference in some situations, but I really don't like new constructs that don't add much clarity to the code you read. Coffee Mugshot fucked around with this message at 19:46 on Aug 11, 2017 |
# ? Aug 11, 2017 19:40 |
TooMuchAbstraction posted:Close: things is falsy Wrong, actually. Else means 'no break': Python code:
I do like for/else; Python code:
Python code:
On the other hand, I do like try/except/else/finally; I firmly believe that try blocks should be as small as possible. Python code:
Eela6 fucked around with this message at 20:00 on Aug 11, 2017 |
|
# ? Aug 11, 2017 19:45 |
|
Having a special place for code that only runs if you don't break from a for loop can actually be quite handy. If more languages had a construct like it I think for...else would get a lot of use. The only real problem with it in python is that basically no other language has a similar construct so people don't expect it and don't have a good idea of what its intended use is.
|
# ? Aug 11, 2017 19:57 |
|
necrotic posted:I know how it happens, but not someone does the third change and goes "gently caress that". I've all but banned the use of unless in our code base except in basic guard conditions. Affirmatives or GTFO. I think the unless keyword was a mistake but I can't even tolerate double negatives, like an if with a negative condition and an else block. Just swap the blocks and make it an affirmative condition.
|
# ? Aug 11, 2017 20:28 |
|
but do you consider "foo != null" an affirmative or negative condition
|
# ? Aug 11, 2017 20:38 |
|
Doom Mathematic posted:I think the unless keyword was a mistake but I can't even tolerate double negatives, like an if with a negative condition and an else block. Just swap the blocks and make it an affirmative condition. Suspicious Dish posted:but do you consider "foo != null" an affirmative or negative condition IMO: if block should be the 'logically normal' case, else block should be the 'exceptional' case. Affirmatiive/negative has nothing to do with it. "What we expect to do" should come before "what we might have to do." This sorts out the usage of 'unless' as well.
|
# ? Aug 11, 2017 21:01 |
|
Suspicious Dish posted:but do you consider "foo != null" an affirmative or negative condition A negative condition. As in: code:
|
# ? Aug 11, 2017 21:23 |
|
One of the more common uses of "if" in my code is to short-circuit blocks, e.g.code:
In fact, I wouldn't be surprised if I use this kind of conditional more often than I use conditionals with both if and else blocks.
|
# ? Aug 11, 2017 21:25 |
|
I have a more horrible horror for you. Why would someone commit edited vendored code. At least vendor it then edit it, instead of both in the same commit. Comments? Tests? What are those?
|
# ? Aug 11, 2017 21:33 |
|
Doom Mathematic posted:I think the unless keyword was a mistake but I can't even tolerate double negatives, like an if with a negative condition and an else block. Just swap the blocks and make it an affirmative condition.
|
# ? Aug 11, 2017 22:14 |
|
Programming languages have "if" and "unless" for the same reason that English does.
|
# ? Aug 11, 2017 22:24 |
Bongo Bill posted:Programming languages have "if" and "unless" for the same reason that English does. "it seemed like a good idea at the time"
|
|
# ? Aug 11, 2017 23:46 |
|
Eela6 posted:"it seemed like a good idea at the time" Someone started using it, other people thought it was a good idea, and just like that there's yet another dialect we have to support.
|
# ? Aug 11, 2017 23:49 |
|
"Unless" I can deal with, it's "until" that I have to think hard about, multiple times.
|
# ? Aug 12, 2017 00:02 |
|
ExcessBLarg! posted:"Unless" I can deal with, it's "until" that I have to think hard about, multiple times. Why? It's just 'while not', and unlike 'unless' it can only be used once so it's about as harmless as syntactic sugar gets. code:
|
# ? Aug 12, 2017 09:26 |
|
NihilCredo posted:Yes. Yes what? Yes, sir! Sorry, old Prolog joke.
|
# ? Aug 12, 2017 12:59 |
|
Bongo Bill posted:I have a more horrible horror for you. Why would someone commit edited vendored code. At least vendor it then edit it, instead of both in the same commit. Comments? Tests? What are those? What does vendoring mean?
|
# ? Aug 12, 2017 15:03 |
taqueso posted:What does vendoring mean? Making a copy of the code for a 3rd-party dependency and adding it wholesale to your own code repository. Often also adding integration into your own build system, as well as perhaps some patches. Somewhat like a fork, but it's not the primary project. The proper way to "vendor" a library is to first add the original, untouched code as one single commit, perhaps even in a branch of its own and then integrate that branch into the main repository, and then apply your own patches on top of that but not in the branch. When the vendor then releases a new version, you copy the new version on top of the original in the vendor branch, and you can now do a diff from the vendor branch to the working repository.
|
|
# ? Aug 12, 2017 15:15 |
|
nielsm posted:Making a copy of the code for a 3rd-party dependency and adding it wholesale to your own code repository. Often also adding integration into your own build system, as well as perhaps some patches. Somewhat like a fork, but it's not the primary project. Branching for a third party library makes sense, but what is the best-practice for managing (re-)applying changes you make to that library, when you update the version? I can think of a few different ways, but they all effectively result in potentially having to fix the same merge conflicts (your changes) with every new version. Or is that something you just have to do?
|
# ? Aug 12, 2017 16:53 |
Sure, if you have your own patches for a 3rd party library, obviously you have to port those patches over to new versions if you want to use those new versions. Proper vendoring-workflows in your SCM system just helps you figure out what those changes are and merge them. In the case Bongo Bill gives they are doing vendoring wrong, by only committing already-patched vendor code. That obstructs the SCM helping with patch management.
|
|
# ? Aug 12, 2017 17:10 |
|
TheBlackVegetable posted:Branching for a third party library makes sense, but what is the best-practice for managing (re-)applying changes you make to that library, when you update the version? I can think of a few different ways, but they all effectively result in potentially having to fix the same merge conflicts (your changes) with every new version. Or is that something you just have to do? You shouldn't have to fix the same merge conflicts every time. You have a vendor branch with commits vendor_v1, vendor_v2 etc that has the unmodified third-party stuff. When the vendor releases a new version, you commit vendor_v3 and merge it to your main branch. Then the only merge conflicts you have to deal with are in places where the vendor has changed things since vendor_v2 was released, which hopefully isn't too much.
|
# ? Aug 12, 2017 20:58 |
|
Wont that remove whatever changes you had to make? If there's conflicts in your changes then it's simpler, but without conflicts you'll just straight up lose your changes.
|
# ? Aug 12, 2017 22:11 |
|
necrotic posted:Wont that remove whatever changes you had to make? If there's conflicts in your changes then it's simpler, but without conflicts you'll just straight up lose your changes. No, that's what would happen if you just applied the new version to the main branch. With the separate branch you avoid the problem. Example. Vendor version 1: code:
code:
code:
code:
code:
|
# ? Aug 12, 2017 22:52 |
|
necrotic posted:Wont that remove whatever changes you had to make? If there's conflicts in your changes then it's simpler, but without conflicts you'll just straight up lose your changes. What version control system do you use? I ask because I think everyone needs to know so they can stay away from it.
|
# ? Aug 13, 2017 05:11 |
|
Jabor posted:What version control system do you use? I was tired and interpreted how it would work wrong. But I use git, a known bad scm.
|
# ? Aug 13, 2017 06:35 |
|
how does that vendoring workflow account for other changes to the project? the original vendor branch would be way out of date when v2 comes out, so you can't just merge it.
|
# ? Aug 13, 2017 07:49 |
|
NihilCredo posted:Then when you merge in the branch back onto the main one, the Squeeze() is from version 1, your SCM recognises it as older code, and doesn't make you solve it. Thanks, that makes sense.
|
# ? Aug 13, 2017 10:44 |
|
necrotic posted:I was tired and interpreted how it would work wrong. git is good
|
# ? Aug 13, 2017 12:06 |
|
Nobody actually understands how git works.
|
# ? Aug 13, 2017 15:07 |
|
SupSuper posted:Nobody actually understands how git works. I hope Junio Hamano does! The explanation of Git that really clicked for me is one that emphasized that it's a content-addressable file system. This helped me to stop thinking of it less as a VCS and more in the abstract, where my branch pointers are soft links pointing to particular inodes/blobs inside Git. Combining that knowledge with the reflog was what really helped me to feel comfortable with Git and get away from the mentality of going straight to git clone this/thing/all/over/again as the first solution to any problem. (Now it is the second, after git reset --hard HEAD@{somereflogreference}.)
|
# ? Aug 13, 2017 15:35 |
|
|
# ? Jun 7, 2024 23:29 |
|
It's difficult to git yourself into a situation you can't escape with the reflog.
|
# ? Aug 13, 2017 21:02 |