this post was submitted on 01 Sep 2023
336 points (96.2% liked)

Programming

17540 readers
70 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 41 points 1 year ago (6 children)

Go with what works

Error messages should contain the information that caused the error. Your average Microsoft error "error 37253" is worthless to me

Keep functions or methods short. Anything longer than 20 - 50 lines is likely too long

Comment why is happening, not what

PHP is actually a really nice language to work with both for web and command line utils

Don't over engineer, KISS. Keep It Simple Stupid

SOLID is quite okay but sometimes there are solid reasons to break those rules

MVC is a PITA in practice, avoid it when possible

[–] [email protected] 19 points 1 year ago (1 children)

PHP is actually a really nice language to work with both for web and command line utils

Pervert.

[–] [email protected] 1 points 1 year ago (1 children)

Yeah, why?

I know it's popular to bitch on php but I've found it's all for the wrong reasons. The vast majority of the internet still runs on it and it's a breeze to work with, I love it. It's safe, it's fast, it's great.

I've worked with a variety of JavaScript frameworks and they all give me headaches.

[–] [email protected] 8 points 1 year ago (1 children)

It's just that it's an ugly and weak language, overly verbose, and riddled with inconsistencies. There are few good things you can do in PHP without huge frameworks.

[–] [email protected] 2 points 1 year ago (1 children)

Not sure what qualifies as ugly but I find PHP codes much easier to read than JavaScript (if that is what you meant)

If with weak you mean weak typed then you're partially correct: most of it can be typed and ever since .. I dunno, years ago, I've worked exclusively with strict typing. Things have improved considerably on that front

What part is verbose? Genuine curiosity

The inconsistencies are true. It's also PHP's strength that they kept everything like that and kept everything compatible. Every JavaScript framework I have worked with caused the weekly update nightmare headaches where 5 bugs were resolved, but now 10 more were added due to changing method calls. I hated it and I love PHP for at least keeping that consistency. Over time they have worked little by little to mitigate things but at the core, yes, you have function call inconsistencies. However, good editors these days for that for you and tell you the function name and give you the parameter order.

Then that there are few good things you can dowithout frameworks is nonsense.

If you want to do it right you use a framework, but that goes for every language. But I've sen and worked on (admittedly a horrible) system that would scrape millions of pages per day and its first version was just hacked together code. Ugly but super quick and simple, no frameworks. I've built many similar systems and sites like it over the years.

Now I recently built my own new framework in PHP, all strict, and it's just fast and beautiful

[–] [email protected] 5 points 1 year ago (1 children)

You're comparing to only JavaScript, have you worked with another language like python, ruby, lisp, rust? Maybe then you'd see what I mean.

By verbose I mean that mostly PHP lacks syntactic sugar, mostly it lacks powerful features of other languages. You can mostly write very simple procedural code.

[–] [email protected] 1 points 1 year ago (1 children)

Well I compare to JavaScript because that's what most people bring up. On web development, I guess JavaScript is the biggest competitor.

I've worked with many languages. I even worked with assembly for a while in another life over 25 years ago, I worked with visual basic, .net, c, c++, Java, JavaScript and it's many frameworks, loads other more obscure languages too, and I've played with some python over the years. Still though, php has my favorite since a loooong time

Can you give an example of missing syntactic sugar or features that are missing?

[–] [email protected] 1 points 1 year ago (1 children)

Type hints and comprehensions as in Python, borrow checker, traits, code interface checking in Rust. Most functional features.

IDK; I just don't like anything about PHP and I have worked with it. It seems bad at every task.

[–] [email protected] 1 points 1 year ago (1 children)

Type hinting? There. Traits? There. Interfaces? There. I could go on but PHP has all these features that people keep saying are missing.

I'm not saying you don't have to like PHP, everyone likes there own labgua and that's fine.

However, people keep making shit up about phpt and then use that shit to smear it and it's annoying. PHP is great for web sites, small and complicated, it's great for command line scripting, it's great for a large list of tasks and it seems that what you need is there.

[–] [email protected] 1 points 1 year ago (1 children)

It doesn't really count if you need a huge framework for it. Frankly I never saw PHP used well, and I never saw it do anything better than other languages can do.

[–] [email protected] 1 points 1 year ago

It doesn't need a huge framework for any of the things I mentioned.

I use my own (rather small still, really) framework to make things easier, like you'd do for any larger projects.

But I can (and have) on many occasions just slap something together as well

[–] [email protected] 8 points 1 year ago (1 children)

Hahaha this is great! All points are basically entirely obvious and common sense and then you hit us with that ridiculous statement about PHP. Outrageous!

[–] [email protected] 2 points 1 year ago (2 children)

From what I've seen is that 99% of the PHP hate is people parroting slogans others came up with, and the rest is that there are inconsistencies with the function signatures.

That last part is very true, of course, but not really an issue with modern editors as they will already tell you what's expected. On the other hand, the inconsistencies are still there for a reason: compatibility. JavaScript what's a nightmare to work with because every week an update would break shit because of changing method signatures in JavaScript packages. PHP always worked and remained working because it changed so little in that respect.

In all other areas it hugely improved and matured over the years, just like all programming languages.

So yeah, I find the PHP hate childish, really.

[–] [email protected] 7 points 1 year ago (1 children)

Honestly, “it’s better than JavaScript” is a pretty low bar.

I don’t like PHP because I think the syntax is ugly and I’ve only used it on systems that are old and a pain to maintain, but I’ll also very freely admit that I have absolutely not written enough PHP to have an informed opinion on it as a language.

[–] [email protected] 1 points 1 year ago

True enough on JavaScript but I mention it because people always take that for comparison. I've used it for hundreds of projects now and for me it's become my default goto language because I can slap together anything with it. It now has good (optional but encouraged) type safety, which greatly improves code quality so yeah.. love it

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago) (1 children)

PHP grew "organically" out of a perl library. There was never a consistent plan/idea about the set of abstractions it provides, the type system, builtin functions etc.. Everything has been bolted on here and there, some additions good, some bad, some terrible pitfalls. A language with builtin operators that are basically unusable (comparison!) and where some functions return false when the input is invalid, is really fundamentally broken. I agree that many of the worst failures of PHP have been (kind of) fixed after PHP5 and that's nice for large existing PHP codebases (mediawiki, wordpress, nextcloud, typo3). But I just can't understand why one would start new projects in PHP in a world where so many very well designed and well thought through languages exist.

Edit: First sentence is misleading. Of course it wasn't a perl lib, but basically a thrown together bunch of functionality, unified into one package, so it can replace using various perl libraries. The syntax was also very inspired by perl.

[–] [email protected] 1 points 1 year ago (1 children)

Yes, PHPs beginnings were very messy and even today we see results from that.

But PHP was and remains hugely popular because it's so easy and fast to work with and today it is very nicely designed and worked out. Yeah there are many details open but editors help you out with that. Other languages may be more consistent at the core but they have their own issues. JavaScript is a nightmare to work with for me, personally, but I o dont bitch about it every opportunity I get.

I guess I'm just slightly annoyed with people complaining about PHP while it's just another language and it's success speaks for itself

[–] [email protected] 1 points 1 year ago (1 children)

Yes, JS is equally terrible! At least we can agree on that :-P

And I also understand that PHP (just like most technologies) can be very efficient to work with if you are used to it and know it very well.

[–] [email protected] 1 points 1 year ago

Well, if it comes to web development (my main focus since the last decade at least) I think it's fair to say there is little that nears PHP (or, begrudgingly, JavaScript)in functionality. With current frameworks (my own included) I can churn out highly complicated and fast sites in no time. Can't say that for many other languages.

Java? "Fast"? Lol no. "No time"? Lolol no.

Python? Honestly I have too little experience with it to say, but at least frameworkoptions are much more limited anyway

[–] [email protected] 8 points 1 year ago (2 children)

I don't have issue with methods being 200 lines, as long as they have a singel concept and is easy to follow.

[–] [email protected] 6 points 1 year ago

If the method does a long thing, the keep it long. I do a lot of data analysis and simulation, and so often people who came before had this urge to shorten methods, so we get:

def do_calculation(N, X, y, z, a, b, c):
    # Setup stuff
    for i in range(N):
        calclation(X[i], y, z, a, b, c)`

Sometimes there's a place for that, like if calculation could be swapped for a different function, or if calculation is used all over the program. It's a pretty good clue that something is up though when the signatures are almost identical. Of course, that has just led to people writing:

def do_calculation(big_struct):
    read_data(big_struct)
    calculate(big_struct)
    write_data(big_struct)
[–] [email protected] 2 points 1 year ago

There are various exceptions where up to 200 lines is still okay, yes. The 50 lines rule is more a good rule of thumb.

[–] [email protected] 7 points 1 year ago

Keep functions or methods short. Anything longer than 20 - 50 lines is likely too long

If it doesn't fit on my screen it's too long.

[–] [email protected] 1 points 1 year ago (1 children)

PHP the language has become pretty nice, but I recently had to work with a PHP CMS deployment, and it was an absolute pain to do. PHP frameworks seem to still exist in a world where you manually upload code to a manually configured server running apache. Dockerizing the CMS (uses Symfony) is/was an absolute pain.

[–] [email protected] 2 points 1 year ago

I know that there are loads of solutions out there that can do this for you, though I don't have much experience with it myself directly. Not a great fan of docker, still, as it's not a requirement and in many cases that extra piece that fails and then is a PITA to fix.

I'll look to include it in my own framework, though

[–] [email protected] -2 points 1 year ago* (last edited 1 year ago) (2 children)

Your average Microsoft error “error 37253” is worthless to me

This is a security thing. A descriptive error message is useful for troubleshooting, but an error message that is useful enough can also give away information about architecture (especially if the application uses remote resources). Instead, provide an error code and have the user contact support to look up what the error means, and support can walk the user through troubleshooting without revealing architecture info.

Another reason can be i18n/l10n: Instead of keeping translations for thousands of error messages, you just need to translate "An Error Has Occurred: {errnum}"

[–] [email protected] 4 points 1 year ago (1 children)

Those benefits both make sense, but are those really the original motivation for Microsoft designing the Blue Screen of Death this way? They sound more like retroactive justifications, especially since BSODs were around well before security and internationalization were common concerns.

[–] [email protected] 3 points 1 year ago

Linux has something similar, kernel panics. However, with Linux you get useful information dumped on your screen.

Nothing gets logged on Linux either, just like windows and that makes sense. The kernel itself messed up and can't trust its own memory anymore. Writing to disk may cause you to fuck up your disk, so you simply stop everything.

Still though, Linux dumps useful info whereas windows just gives you this dumb useless code.

[–] [email protected] 0 points 1 year ago

Not when it's my own computer. My computer needs to give me useful messages.If it's a website then the site MUST log correctly in the log files...

If it's a translation issue then just use English, everyone that can understand logs can (or at least should) understand that