Damn, now that we put it like this, it sure sounds like a lot of work to keep this entire thing up. What if we employed the computer to do these checks for us? We just need to tell it what pattern to look for, and it could make sure we always conform to this pattern. In fact, we could easily create entire classes of object in this way. Let's re-write our code to be more OOP.
class User {
// These are _properties_ - or what were previously entries in our hash map.
// They are marked as `private`. That means we cannot just reach into an instance
// of this class (a.k.a., our object) and change it - we _must_ go through the
// `setEmail` method to change it ¹
private $name;
private $email;
// This is what was once our `user_init` method.
public function __construct($name, $email = null) {
// This can be written much more sailently in recent PHP versions.
// Figuring out how is an exercise for the reader.
$this->name = $name;
$this->email = $email;
}
// We used to call this `user_set_email`.
public function setEmail($email) { // Note the ommission of the $self parameter
// TODO: Validate email address
$this->email = $email; // Note $this instead of $self, and the member access syntax
}
// This was... well, you get it.
public function isValid() {
return strlen($this->name) > 0 && $this->email != null;
}
// ¹ Shenanigans with poking internals through reflection notwithstanding.
}
// Let's use it!
$bobby = new User("bobby-tables");
var_dump($bobby->isValid()); // => bool(false)
$bobby->setEmail("bobby@example.com");
var_dump($bobby->isValid()); // => bool(true)
$bobby->email = "badEmail!"; // => Fatal error: Uncaught Error: Cannot access private property User::$email
$post = ["title" => "Hello, world!"];
$post->setEmail("what?"); // => Fatal error: Uncaught Error: Call to a member function setEmail() on array
That's all it is. An object is a collection of data that makes sense to hold together with actions performed on it. There is, of course, much more to it that you can do with classes and objects, but at its core, this is how you are supposed to think of them. When I was starting out, I firmly believed OOP is magic and didn't understand the fundementals of it, and thinking of it in this way really helped. I hope it helps you as well.
This is a very boring object. We can't do much with it. Let's add some behavior to it.
// A user is valid if they have a name longer than 2 characters and a set email.
function user_is_valid(&$self) {
return strlen($self["name"]) > 2 && $self["email"] != null;
}
// Sets a user's email address.
function user_set_email(&$self, $email) {
// TODO: validate email
$self["email"] = $email;
}
var_dump(user_is_valid($bobby)); // => bool(false)
user_set_email($bobby, "bobby@example.com");
var_dump(user_is_valid($bobby)); // => bool(true)
So far so good. We could say we have a User object with name and email properties, and the two methods on this User are set_email and is_valid. Since this went so well, let's make another one, and this time we will even make him valid at initialization.
$wizard = [
"naem" => "bloodninja",
"email" => "rpgenjoyer@example.com",
];
var_dump(user_is_valid($wizard)); // => Warning: Undefined array key "name" in <file> on line 9
Wait... what? How? This makes perfect sen- ah, damn. Looks like we made a typo. Old eyes, I suppose. Maybe it's better to have a function that handles creating these objects.
Oh, hey, that's much better. Now, as long as we remember to always create users with user_init(), we should be fine. Oh, and I guess that we also need to keep track of which variables are users and which ones are representing something else. We don't want to accidentally call user_is_valid on a Post, for example. Well, that, and we also need to document this very well so that anyone else who comes after us knows how to handle this. Come to think of it, we also want to make sure that the email on our user object is valid if it's present - right now, even if we enforce this in our user_set_email function, our co-worker who's having a rough day and is not thinking straight can just come in and do $user["email"] = $_POST["email"] and forget to validate it.
Well, "Linux" is a very generic and broad term these days. The kernel itself is a massive project with many different moving parts, and then there's dozens of tools and applications that you might use to cover certain use cases. I don't know what's your experience like so I'll start from the basics, even though since you're running Arch you probably already know a thing or two ;)
From my experience, putting formal education aside, the best way to learn is by doing. If your Arch server works for you, think about what you could do as an external attacker to topple it over. Can you log in as root with a password? can you brute force the password prompt? do you get notified when your CPU usage is unusually high, or when the root account does something, or when you log in from an unusual IP, what ports are open on your machine and what's listening on them... coming up with scenarios like that and then reasoning about what you're doing to prevent them. Same with any services you might be running, e.g. if you're running OpenVPN look through potential OpenVPN attack vectors and make sure that your usage of it aligns with what the official resources prescribe.
Of course this is much simpler when you have a mentor, so the best best way to learn is probably to be hired as a junior (Dev)Ops engineer and ideally someone will hold you back before you make a mistake or let you make one in a safe way. A good resource for that is the DevOps roadmap that will point you in the right direction, but you will still have to do your own research and apply what you've learned independently. You should follow the order, that is to say - seeing 4 VMs spin up via Terraform and then auto applying configuration on them using Ansible looks very cool, but if you don't know why is it doing that and how, you will just get frustrated ;)
Hey dude if it works for you then cool, but as I wrote in the other comment I would really really think twice and thrice about exposing an Arch server with homebrew configuration to the internet, because the internet is a scary place and it is extremely easy to wave your hand at certain potential issues (or, even worse, not even be aware of them) until it bites you in your behind.
All of the extra stuff running with Debian and Ubuntu and CentOS servers isn't there because it's bloat and Canonical/RH wanna sell you solutions, it's there as a direct response to very real issues that exist on any machine hooked up to the internet.
I wouldn't want to have my personal data leaked to the entire Internet because I misconfigured something and then be told that I should just have read 200 manpages to get it right, otherwise I am a big dumb idiot for not even RTFM-ing.
Don't get me wrong, I love Arch, I use it on my desktop PC and it's a joy to tinker with it, but if I am putting any data that I care about even slightly accessible to the outside world I want a system that ships with strict defaults and that won't let me shoot myself in the foot easily.
You can’t “remove swift”, it’s not an interpreted language. And there’s no reason for macOS to ship with PHP, Python, Ruby or anything of the sort - the vast majority of users do not need them, and for power users and programmers it’s trivial to install them
I agree - in the age where a $35 Raspberry Pi has 2GB of RAM, nitpicking about 16 or 32MB in an interpreted/JIT language like PHP reeks of elitist bullshit, and if there’s one trend I can’t stand in the programming community it’s the elitism. I understand being concerned about performance, but if someone is that constrained for resources, perhaps they should use C or something similar. But more often than not, it’s elitism - the same kind of people who complain during code review that using single quotes is more efficient than using double quotes, and then completely skip over a O(n2 ) algorithm because they don’t really care, they just want to appear “knowledgeable”.
Well yes, I agree, and they should also rework the entire standard library so that it has sane function names and calling conventions, but it won’t ever happen because PHP is big on backwards compatibility.
MIT license is not WTFPL, it's asking for the absolute minimum of common courtesy to attribute the ownership of the code - failing to do even that is not just copyright violation but also plain rude.
There's always going to be a user for whom your web page is broken because of their particular setup. document.querySelector() works for everything older than IE 7, which is more than perfectly fine. Backwards compatibility is good but after some point, it's a little bit of an overkill to sink in dozens of hours of your development time for a feature not used by the vast majority of your audience.
In other words, if the cost of you coding and maintaining a backwards compatibility feature is larger than the potential earnings from it, then you really shouldn't do it.
str_contains is worth creating a reddit account to be upset about but archaic unnecessary functions that no one ever uses yet are still a part of the stdlib, such as str_rot13, are not, this is truly peak PHP-posting.
One important ORM difference is identity-map pattern and datatype abstraction in Doctrine. I will always trade speed for comfort in these 2 features.
You mean, the Data Mapper pattern used by Doctrine fits your use case better than the Active Record pattern used by Eloquent? Perfectly fine as long as you are productive with it - but don't fool yourself into thinking that a DM pattern lets you substitute out Doctrine for something else easily, you are just as tied into your library as you are with something like Eloquent.
In my opinion, HCL is far more reasonable than YML. The problem is that they are using it as a programming language for a CI tool instead of as a configuration tool which it was meant to be.
Honestly? If it was a regular text post I would hate it. There are already plenty of ads for jobs on Facebook, Instagram, Twitter and whatnot and Reddit is a platform for sharing content, not ads.
If it's a paid Reddit ad that targets specific subreddits and demographics then sure, but I would definitely downvote a job posting as a natural text post.
I'd add that IoC is used to loosen coupling between objects, not to turn a codebase into a scattering of ideally isolated objects that you then assemble in thousands of lines of services.yml. Dependency injection comes with both a mental and code overhead, and it's important to know when using DI brings no immediate or short-term value.
If you foresee using multiple different classes with the same interface then DI is the way to go. On the other hand, I have often run into cases (and caused them myself) where a simple "new" would have sufficed. Implementing an interface at that point led to a bad abstraction at best, and a "good code theater" at worst where people thought they were writing good code because they were using DI and interfaces, yet the classes they wrote were still tightly coupled together and knew about each other's internals. When it was time to refactor we had to battle both the assumption that was wrong from the start (existing code compels you to write more code like it) and the actual code that was perhaps pretty to look at but flawed inside out.
tl;dr everything in moderation including moderation
Damn, now that we put it like this, it sure sounds like a lot of work to keep this entire thing up. What if we employed the computer to do these checks for us? We just need to tell it what pattern to look for, and it could make sure we always conform to this pattern. In fact, we could easily create entire classes of object in this way. Let's re-write our code to be more OOP.
That's all it is. An object is a collection of data that makes sense to hold together with actions performed on it. There is, of course, much more to it that you can do with classes and objects, but at its core, this is how you are supposed to think of them. When I was starting out, I firmly believed OOP is magic and didn't understand the fundementals of it, and thinking of it in this way really helped. I hope it helps you as well.
An object is a combination of data and actions on that data.
Here's a very boring object that represents a user with a name and an email.
This is a very boring object. We can't do much with it. Let's add some behavior to it.
So far so good. We could say we have a User object with
nameandemailproperties, and the two methods on this User areset_emailandis_valid. Since this went so well, let's make another one, and this time we will even make him valid at initialization.Wait... what? How? This makes perfect sen- ah, damn. Looks like we made a typo. Old eyes, I suppose. Maybe it's better to have a function that handles creating these objects.
Oh, hey, that's much better. Now, as long as we remember to always create users with
user_init(), we should be fine. Oh, and I guess that we also need to keep track of which variables are users and which ones are representing something else. We don't want to accidentally calluser_is_validon aPost, for example. Well, that, and we also need to document this very well so that anyone else who comes after us knows how to handle this. Come to think of it, we also want to make sure that the email on our user object is valid if it's present - right now, even if we enforce this in ouruser_set_emailfunction, our co-worker who's having a rough day and is not thinking straight can just come in and do$user["email"] = $_POST["email"]and forget to validate it.(cont.)
If you have 45 minutes to spare, this talk (The Tragedy of systemd) will explain a lot of things about
systemdand previous init systems. :)Good luck!
Well, "Linux" is a very generic and broad term these days. The kernel itself is a massive project with many different moving parts, and then there's dozens of tools and applications that you might use to cover certain use cases. I don't know what's your experience like so I'll start from the basics, even though since you're running Arch you probably already know a thing or two ;)
From my experience, putting formal education aside, the best way to learn is by doing. If your Arch server works for you, think about what you could do as an external attacker to topple it over. Can you log in as
rootwith a password? can you brute force the password prompt? do you get notified when your CPU usage is unusually high, or when the root account does something, or when you log in from an unusual IP, what ports are open on your machine and what's listening on them... coming up with scenarios like that and then reasoning about what you're doing to prevent them. Same with any services you might be running, e.g. if you're running OpenVPN look through potential OpenVPN attack vectors and make sure that your usage of it aligns with what the official resources prescribe.Of course this is much simpler when you have a mentor, so the best best way to learn is probably to be hired as a junior (Dev)Ops engineer and ideally someone will hold you back before you make a mistake or let you make one in a safe way. A good resource for that is the DevOps roadmap that will point you in the right direction, but you will still have to do your own research and apply what you've learned independently. You should follow the order, that is to say - seeing 4 VMs spin up via Terraform and then auto applying configuration on them using Ansible looks very cool, but if you don't know why is it doing that and how, you will just get frustrated ;)
Hey dude if it works for you then cool, but as I wrote in the other comment I would really really think twice and thrice about exposing an Arch server with homebrew configuration to the internet, because the internet is a scary place and it is extremely easy to wave your hand at certain potential issues (or, even worse, not even be aware of them) until it bites you in your behind.
All of the extra stuff running with Debian and Ubuntu and CentOS servers isn't there because it's bloat and Canonical/RH wanna sell you solutions, it's there as a direct response to very real issues that exist on any machine hooked up to the internet.
I wouldn't want to have my personal data leaked to the entire Internet because I misconfigured something and then be told that I should just have read 200 manpages to get it right, otherwise I am a big dumb idiot for not even RTFM-ing.
Don't get me wrong, I love Arch, I use it on my desktop PC and it's a joy to tinker with it, but if I am putting any data that I care about even slightly accessible to the outside world I want a system that ships with strict defaults and that won't let me shoot myself in the foot easily.
I don't think anyone sane or over the age of 22 uses Arch as a server.
But you're using Arch Linux. That is what we do here.
You can’t “remove swift”, it’s not an interpreted language. And there’s no reason for macOS to ship with PHP, Python, Ruby or anything of the sort - the vast majority of users do not need them, and for power users and programmers it’s trivial to install them
What would you say is an average salary for a mid to senior level dev?
https://phil.tech/2013/t-paamayim-nekudotayim-v-sanity/
I agree - in the age where a $35 Raspberry Pi has 2GB of RAM, nitpicking about 16 or 32MB in an interpreted/JIT language like PHP reeks of elitist bullshit, and if there’s one trend I can’t stand in the programming community it’s the elitism. I understand being concerned about performance, but if someone is that constrained for resources, perhaps they should use C or something similar. But more often than not, it’s elitism - the same kind of people who complain during code review that using single quotes is more efficient than using double quotes, and then completely skip over a O(n2 ) algorithm because they don’t really care, they just want to appear “knowledgeable”.
Well yes, I agree, and they should also rework the entire standard library so that it has sane function names and calling conventions, but it won’t ever happen because PHP is big on backwards compatibility.
@is an operator already.MIT license is not WTFPL, it's asking for the absolute minimum of common courtesy to attribute the ownership of the code - failing to do even that is not just copyright violation but also plain rude.
There's always going to be a user for whom your web page is broken because of their particular setup.
document.querySelector()works for everything older than IE 7, which is more than perfectly fine. Backwards compatibility is good but after some point, it's a little bit of an overkill to sink in dozens of hours of your development time for a feature not used by the vast majority of your audience.In other words, if the cost of you coding and maintaining a backwards compatibility feature is larger than the potential earnings from it, then you really shouldn't do it.
str_containsis worth creating a reddit account to be upset about but archaic unnecessary functions that no one ever uses yet are still a part of the stdlib, such asstr_rot13, are not, this is truly peak PHP-posting.You mean, the Data Mapper pattern used by Doctrine fits your use case better than the Active Record pattern used by Eloquent? Perfectly fine as long as you are productive with it - but don't fool yourself into thinking that a DM pattern lets you substitute out Doctrine for something else easily, you are just as tied into your library as you are with something like Eloquent.
how does alacritty compare to kitty, which is also GPU accelerated?
Don't JetBrains tools have auto-accept first suggestion functionality with something like
Alt+Enter?In my opinion, HCL is far more reasonable than YML. The problem is that they are using it as a programming language for a CI tool instead of as a configuration tool which it was meant to be.
same, i was at the 2017 one too where Rasmus spoke as well, missed my chance for a selfie with him :(
Honestly? If it was a regular text post I would hate it. There are already plenty of ads for jobs on Facebook, Instagram, Twitter and whatnot and Reddit is a platform for sharing content, not ads.
If it's a paid Reddit ad that targets specific subreddits and demographics then sure, but I would definitely downvote a job posting as a natural text post.
I'd add that IoC is used to loosen coupling between objects, not to turn a codebase into a scattering of ideally isolated objects that you then assemble in thousands of lines of services.yml. Dependency injection comes with both a mental and code overhead, and it's important to know when using DI brings no immediate or short-term value.
If you foresee using multiple different classes with the same interface then DI is the way to go. On the other hand, I have often run into cases (and caused them myself) where a simple "new" would have sufficed. Implementing an interface at that point led to a bad abstraction at best, and a "good code theater" at worst where people thought they were writing good code because they were using DI and interfaces, yet the classes they wrote were still tightly coupled together and knew about each other's internals. When it was time to refactor we had to battle both the assumption that was wrong from the start (existing code compels you to write more code like it) and the actual code that was perhaps pretty to look at but flawed inside out.
tl;dr everything in moderation including moderation
Counterpoint: Please do consider using the GPL or the LGPL. Everyone benefits from contributions to the open-source ecosystem.