Live data from Hacker News

Re: Moving from PHP to Go and Back Again

blog.breakthru.solutions

191–200 of 281 posts

Re: Re: Moving from PHP to Go and Back Again

#191
post #54

Earlier quoted context omitted.

By that definition every language has a runtime (yes, including C with crt0.o). Something has to set up the stack, enter the main() function etc. So how do you differentiate a systems language runtime? One that is bundled with the OS? Or is thin enough by some arbitrary measure?

> is thin enough by some arbitrary measure? Colloquially, this. There's historically been a fairly big gap between "very little runtime" and "more runtime", so "no runtime" and "runtime" are what people say. That said, the word is generally ill-defined; some people use it to mean "interpreter" or "vm" rather than the classic definition, which is (as you say) that every non-assembly language has a runtime.

Actually in the world of micro-code and uOPs even Assembly can be said to use a "runtime", for specific CPUs. :)

Re: Re: Moving from PHP to Go and Back Again

#192
post #109

Earlier quoted context omitted.

Many people were taught OOP the UML and Java way†, to which the concept of prototype-based inheritance is completely alien, while composition is not even on their radar. † Although they have their fair share of issues, this is not a jab at UML nor Java themselves, but the way things have been taught, terribly, for so many.

What would you consider solid references to learn sane OOP? I have a vague working model of object orientation but a lot of the finer details go straight over my head.

I'm being very serious here, with no sarcasm: Using a language that has an alternate model of OO that either simply doesn't have inheritance, or makes it relatively hard.

IMHO it doesn't matter much how much you read about the differences, until you get in there it won't do much good. This is a good place to have a throwaway project on hand, because your first try is likely to be a very big mess.

If you know an inheritance model and a non-inheritance model, you'll be well on your way to understanding the nuances because you'll have the experience in the field.

(For reference, my personal definition of OO is pretty much any language where you can write object.method(arguments), some kind of polymorphism is made available on that, and that is either the primary or a very important element of design in the language. It's a very expansive definition because I find that having massive definition debates about what OO is to be nothing more than useless flamewars.)

Re: Re: Moving from PHP to Go and Back Again

#193

Earlier quoted context omitted.

Yes that's true. When I was at university we learned about the concept of composition but the reference language for this 'software engineering' course was C++. The whole composition idea felt contrived at that point. Some time later I learned Lua for fun and almost instantly understood what this whole prototype based programming / composition was about :) TLDR: While I learned about composition at university, they f…

JS mixin / Ruby module / C++ mixin style composition are less than excellent, mind - throwing all the methods from multiple locations into a single scope is a recipe for implicit dependencies. There's an assumption that you won't define any methods that the mixins also define, not only today, but in the future; and even more, you assume that a same-named method won't be defined in multiple mixins, not only today, but…

Which bring us to old school has-a relationship. Nothing wrong with that.

Re: Re: Moving from PHP to Go and Back Again

#194

Earlier quoted context omitted.

> And yet we keep writing Go. Remember that Go is still a niche language, and the majority of programmers will never write a single line of Go. There is a nice trend around Go nowadays, but most people are still writing PHP, Python or Java and Go isn't going to replace any of those.

One could equally remember that Java was a niche language in 2000 used by a few dot-com startups, and even today it has not replaced C++, COBOL, or Fortran. Languages don’t get replaced, people just don’t use them as often for new projects.

> One could equally remember that Java was a niche language in 2000 used by a few dot-com startups, and even today it has not replaced C++, COBOL, or Fortran.

Ouch, the lack of historical accuracy of your comment is painful. Just a few points :

- Sun Microsystem was founded in 1982, it's far from being a dot-com start-up.

- Java was already ubiquitous by 2000, it was embedded in your phones, your credit cards, in your browsers thanks to applets etc.

- in fact it did replace COBOL or C++ for a wide number of applications, not everywhere but it still had a enormous impact on the industry. Netscape even went as far as re-implementing their whole browser in Java[1]. It was a bad idea, but that gives you an idea of the revolutionary impact Java had.

Go is nowhere near where Java was in 2000, by several orders of magnitude. It's not a criticism of Go, I don't even think we'll ever have a language as popular as Java in that time, because in the 90s there was a massive window of opportunity for a language that was at the same time : safe, portable, and licence-free.

[1]: https://www.cnet.com/news/netscape-sharpens-javagator-plans/

Re: Re: Moving from PHP to Go and Back Again

#195
post #190

Some background. I actually wrote a semi-popular book on PHP (published by a major publisher) and have contributed to the core project. And I have spoken at many PHP conferences. Perhaps tellingly, PHP is rarely my first choice anymore. Which I think it a great language (contrary to many opinions) I just find other languages a better choice. Today my language usage looks like this: - Web services / APIs: Node.js [1]…

in latest nodejs there is no a single place to catch exceptions in promise chain, which is very inconvenient.

Could you explain this? We use node everyday and I don't understand what you mean.

Re: Re: Moving from PHP to Go and Back Again

#196
post #189

> Would you rather? > > A – Be able to write new code 50% faster > B – Have 90% less errors in all new code you write For my employer, this is the most important question of the 3, and the answer is A every time.

I guess the answer would depend on how many errors you have in the first place.

If you have a ton of errors, B is going to be more important. If you have relatively few, then A is going to be a lot better.

My employer would probably pick A, too.

But there's a hidden side to this: If it's that much easier to code quickly, it's probably easier to understand the code as well. Which means fixing bugs is faster as well. At least, in my experience.

Re: Re: Moving from PHP to Go and Back Again

#197
post #127

I know this is about the weakest critique possible, but currently using Go, I know my next project won't be in it, simply for the impossibility to put an opening curly brace on its own line. Other languages that don't require semicolons at the end of a line have it, and even if they didn't, I'd rather have to put semicolons manually.. Go is "opinionated" I guess, but so am I. Whatever their target audience is, I'm no…

> One thing I used to hate about PHP but then kinda grew to like was variables being prefixed with a $, as it makes it real easy to distinguish between functions and variables at a glance. This is great for a lot of code but it's probably my biggest complaint about the language these days. PHP supports first-class functions, which is great until you realize all your functions stored in variables have $ at the front.…

Our team uses snake_case for variable names and camelCase for function names in PHP to address that ambiguity.

To me, the limited scope of variables with respect to functions makes debugging and code reading much easier, since everything I need to think about within a function scope is explicitly defined.

Re: Re: Moving from PHP to Go and Back Again

#198
post #86

Earlier quoted context omitted.

Also, very few projects will ever end up at the scale (user base/metrics) that Facebook had. 99% of all PHP software will be fine with a quadcore server with 4GB RAM, running a LAMP stack. This can be scaled as needed (eg moving off mysql, adding a reverse proxy, real load balancing).

I've always been really skeptical of those language performance comparisons which refer to PHP. As stated above PHP7 has similar performance when compared to HHVM which was made by Facebook. Additionally PHP has an amazing performance debugger by FB called xhprof. PHP performance could always be increased hugely by making sure is cache buckets have enough memory (opcode cache, realpath_cache_size). Secondly with any…

> If anyone's ever worked on a project where the performance problem was the language and not IO I'd be really interested in hearing about it, but in my career of making websites I've never ran into this problem yet.

Our company's product is CPU bound, and our language (Python) is definitely inhibiting our ability to meet basic performance goals. I've done a few crude benchmarks and I'm confident that a rewrite in Go would buy us at least a tenfold performance improvement, although the benchmarks themselves suggest it's closer to 100-200X. Besides being faster out of the box, Go is also easier to optimize--better profiling tooling but also the ability to control memory layout, allocations, and dispatch. And that's all without parallelism.

Re: Re: Moving from PHP to Go and Back Again

#199
post #15

Earlier quoted context omitted.

PHP has object checking. This is why I started using value objects in PHP. The VO's I use trow exceptions when you construct them with some bad value. This is great because when you use for example a natural positive integer object you are sure it is one. So now I have 'type checking' and more secure code in PHP.

PHP also supports other type declarations. But using lots of value objects is a good idea anyway. http://php.net/manual/en/functions.arguments.php#functions.a...

Since when does PHP has value types? Aren't all the classes reference types or you mean that Array thingie?

And it is still the case with type declarations, that they make your code actually slower, because the runtime adds asserts in your code which gets evaluated at runtime?

Re: Re: Moving from PHP to Go and Back Again

#200

Some background. I actually wrote a semi-popular book on PHP (published by a major publisher) and have contributed to the core project. And I have spoken at many PHP conferences. Perhaps tellingly, PHP is rarely my first choice anymore. Which I think it a great language (contrary to many opinions) I just find other languages a better choice. Today my language usage looks like this: - Web services / APIs: Node.js [1]…

I think this represents a lot of developers, except some replace PHP with Ruby or Python.
Post reply on HN