- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
There; now all three branches do something usefully different.
Admin
(and yes, the above is valid Python, semicolons are a thing in Python)
Admin
Extended case of 'measure twice, cut once'?
Admin
Nothing to see here. Business rules changed over time, and the devs changed the stuff that business wanted changed, that business don't want to work the same way that business wanted it to work before this business decision change.
Admin
My best guess for such code is always, that it started out with genuinely different code in each branch, and then slowly, through many small commits, converged to do the same on each branch, but nobody ever taking the step of removing them, for whatever strange reason there may be, probably related to badly implemented code-review processes or performance metrics. Or negligence.
With such code I'd be really interested to see the code history leading to it...
Admin
No doubt that removing any of the cases will cause a regression
Admin
In Python, can user.is_owner() do something else before returning a boolean? Like, I don't know, recalculate and set the status of all users, then send a mail to confirm the email? I only know about .Net enterprisey solutions, where the risk to simplify this code would be small, but not 0
Admin
In Python, can user.is_owner() do something else before returning a boolean? Like, I don't know, recalculate and set the status of all users, then send a mail to confirm the email? I only know about .Net enterprisey solutions, where the risk to simplify this code would be small, but not 0
Admin
Sometimes it's not even in the code history, it was added when first making the change and updated to the current version before anyone committed anything.
This happens a lot with less experienced developers who don't like to commit until they're done(a terrible practice but understandable when you're unsure and don't want mistakes in the commit history forever).
Admin
Comment held for moderation.
Admin
As the Scarecrow said,
Admin
We get paid by the pound, so dammit, we're gonna add some pounds.
Admin
Honestly I never understood the appeal of Python beside being a nice language for scripts and people lacking experience or general coding skills. I don't see how it would be well suited for something like HTTP handling but maybe that's just because Python to me is a total black box beyond what I see from time to time and then often have to rewrite into something proper.
Admin
"I got paid by the line."
Admin
I get paid by the bit. My managers thought I was crazy until I switched all code files to UTF-32. :)
Admin
Bold of you to assume that user.is_owner() will return a boolean. I mean, it might, and in a sensible solution it would. But given that we are already on TDWTF, I wouldn't count on that without actually checking the implementation myself.
But yes, there's nothing stopping that function from doing whatever monstrosities someone might have fancied to implement there, including but not limited to the things you listed.
Admin
Python is a programming language, and it can do pretty much anything that other programming languages can do. I don't see why you would think it's less suited for server-side web programming than PHP, Perl, or Ruby.
Admin
The illusion of choice
Admin
"Honestly I never understood the appeal of Python beside being a nice language for scripts and people lacking experience or general coding skills. I don't see how it would be well suited for something like HTTP handling but maybe that's just because Python to me is a total black box beyond what I see from time to time and then often have to rewrite into something proper."
Python is the closest thing we have to "executable pseudocode". In plain English, Python operates on the principle that if the computer can figure out something on its own, it should do that. Sure, it sacrifices a bit of performance but it also leads to fewer lines of code and more easily readable code (the "semantic gap" is smaller). Not every piece of code out there has to be performant. If your code's execution time is 98-99% network requests for example, does it really matter if the code is not as performant as it could be?
Also, I personally find mandating correct indentation instead of leaving it up to the programmer a good thing.
Admin
Mixed bag there. Consistent indentation should be enforced by mandatory code formatting tools, but I find an explicit open/close syntax like C-style
{}
blocks good to have. Basically with proper code-formatting and{}
combined, you have two visual indicators of code structure, which I find to help readability.It also allows powerful programming constructs to be implemented as plain function calls with an anonymous function as argument, which in Python is limited to expression-only functions, due to the syntax not allowing full function definitions in such places.
So where in JavaScript you'd have
in Python you end up with something like
Personally I find the JavaScript version more clear; It communicates “this function definition is only ever needed in this one place, and nowhere else”, while the Python version doesn't communicate that, and it forces me to come up with a name for a function that is used only once.
Another example is “pipe-style processing” (
.map
,.filter
,.foreach
, ...) which in JavaScript make use of full-fledged function expressions to allow a pipe-like postfix notation and allow arbitrary code blocks in the callback functions. You could do something like that with decorators, but function decorators are usually expected to return a function, not a value, so it would feel like abuse of a language feature. And it is directly a consequence of “block structure by indentation”.Admin
And in some languages like Perl, you can do nifty things like
Admin
What version of Perl is that? In the Perl that I used, you were not able to declare parameters like that, but had to do weird stuff like
Exact syntax may be nonsense. Haven't used Perl much since switching to Python for most tasks.
Admin
Since Perl 5.20 IIRC, one can enable sub routine signatures. The older method can still be used and has its uses.
Please see https://perldoc.perl.org/perlsub#Signatures for more info.