Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Look Around You
Jan 19, 2009

Strong Sauce posted:

Read the whole thing:



PHP generally doesn't throw exceptions (and didn't get them until 5) so it'd be even worse to make it throw an exception here since that would stop PHP from generating the rest of the page.

There were 3.5 years between 5.1 and 5.3, in that time PHP released several versions of 5.3 and notified developers to test and address any problems.

Version 5.3.2 04-Mar-2010
Version 5.1.6 24-Aug-2006

How is rasmus being a dick when he already gave a solution for the developer to fix the problem?

As Janin said, php really doesn't deeply care about he difference between strings and numbers and will generally auto convert to integers (usually 0 if they're non numerical). Introducing a breaking change like that is pretty dumb considering it goes against how strings usually behave in PHP. Stuff like this seems pretty par for the course on PHP though.

The person who filed the issue put it best:

quote:

 [2010-01-08 21:26 UTC] endosquid at endosquid dot com
I submit that you may have missed the point:

We are passing a (possibly uninitialized, or null-valued) variable to the function, in hundreds of places and web pages, and we would not expect such a fundamental function to suddenly return a different result. What is unreasonable about expecting a "number formatting" function to default to "0" if given non-numeric or null input, *esp* since that has been the behavior since Day 1?

Also it probably should have returned the empty string all along, returning 0 here doesn't really make sense. A breaking change like this is similarly dumb though, especially his suggested fix, which is pretty :wtf: in and of itself:

quote:

Months? Being a bit dramatic here?

sed -i "s#number_format(#number_format((float)#g" *.php

Adbot
ADBOT LOVES YOU

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

What in the loving gently caress

Rasmus posted:

I think the right solution for you here is to be explicit about casting
your weird inputs to a float. number_format((float)$weird,'0') will
take care of it.
Uh. Here is the prototype for that function:
code:
string number_format ( float $number [, int $decimals = 0 ] )
IT ALREADY CASTS TO FLOAT. If you give it a $number that isn't a float, that $number gets cast to float automatically. This seems to betray a horrible, horrible mistake somewhere deep inside PHP, that "float (float)$number" is somehow going to return a different result than "float (float)$number". This is loving amazing.

The final indignity: the documentation doesn't mention this. For output, it says it outputs a formatted version of number. It does not mention null. Christ, and this was undocumented? What the gently caress?

I say this as a full-time professional PHP programmer, holy poo poo. This single incident is making me to learn another language. What do y'all recommend?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I'm happy with Python.

ToxicFrog
Apr 26, 2008


Golbez posted:

I say this as a full-time professional PHP programmer, holy poo poo. This single incident is making me to learn another language. What do y'all recommend?

Depends on what you want it for. Web development? Ruby (+Rails), Python (+Django or probably dozens of others I haven't tried), if you like some static typing (and who doesn't?) Scala (+Play or, if it has actual documentation now, +Lift).

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

ToxicFrog posted:

Depends on what you want it for. Web development? Ruby (+Rails), Python (+Django or probably dozens of others I haven't tried), if you like some static typing (and who doesn't?) Scala (+Play or, if it has actual documentation now, +Lift).

Web development. Currently rocking PHP/MySQL, and have been wondering about finding a better alternative to MySQL as well.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Without more information about their needs or wants, I always tell people who want to learn a new (or first) language that the answer is Python. However...I can't say for sure whether that's an objective recommendation. Python* is the first language I learned so I may just have a soft spot for it.

*Besides QBasic, but I learned QBasic when I was like 12 and then didn't touch programming for 20 years.

KaneTW
Dec 2, 2011

If you've got the time, throw a look at Haskell. While I haven't done web development with it personally it's a really exciting language.

I'm using Python/Django for web development and it works like a charm.

\/ Postgres is just so much better than mysql

KaneTW fucked around with this message at 16:15 on Jun 22, 2012

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Golbez posted:

Web development. Currently rocking PHP/MySQL, and have been wondering about finding a better alternative to MySQL as well.

Postgres for relational, Mongo for document.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

pokeyman posted:

Postgres for relational, Mongo for document.

I have experience only in relational DBs. Is there a link that explains the second half of your sentence to me like I'm a 5 year old?

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
Do not pick Python for web development. It is a pretty great language, but Django is a enormous piece of poo poo that breaks if you cough on it too hard. Pick Ruby, which is a great language with great support for all sorts of expressive new ways to write code, and gives you Rails, which makes web development so much nicer.

Edit:

Golbez posted:

I have experience only in relational DBs. Is there a link that explains the second half of your sentence to me like I'm a 5 year old?

http://en.wikipedia.org/wiki/MongoDB#Data_manipulation:_collections_and_documents seems pretty good at explaining things.

KaneTW
Dec 2, 2011

Sinestro posted:

Do not pick Python for web development. It is a pretty great language, but Django is a enormous piece of poo poo that breaks if you cough on it too hard. Pick Ruby, which is a great language with great support for all sorts of expressive new ways to write code, and gives you Rails, which makes web development so much nicer.

Edit:


http://en.wikipedia.org/wiki/MongoDB#Data_manipulation:_collections_and_documents seems pretty good at explaining things.

I've been using Django and it didn't seem like a piece of poo poo at all.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
And Redis for key-value.

Golbez posted:

I have experience only in relational DBs. Is there a link that explains the second half of your sentence to me like I'm a 5 year old?

Basically instead of a schema describing tables you have no schema and documents containing whatever you want.

I've never found a page that does what you ask, but here's a recent blog post that does an ok job. Seems relevant too.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Golbez posted:

I have experience only in relational DBs. Is there a link that explains the second half of your sentence to me like I'm a 5 year old?

http://klewel.com/conferences/djangocon-2012/index.php?talkID=9

Skip to slide 18.

Zombywuf
Mar 29, 2008

"Document" and "key-value" databases are the real horror.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.

KaneTW posted:

I've been using Django and it didn't seem like a piece of poo poo at all.

Eevee posted:

Django is a massive beast designed for CMS-likes and other content-rich sites. It has a large ecosystem of pluggable components, built-in everythings from templates to an ORM, and piles of documentation and community resources. Django is generally cited as the Python equivalent to Ruby on Rails. The downside is that convincing it to do things it doesn’t want to do can be… awkward. (Many of the more obtuse questions in #python are caused by attempts to tinker with Django.)

This is pretty much the best description of Django I have read. (Source: here)

He compares to Ruby on Rails, but Rails makes up for it's large size by actually making things easier than working with a barebones framework. To put it another way, Django has all of Rails' complexity, but lacks any of its helpers or most of its utility.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
You have other options besides Django, you know, like Flask and Pyramid. Read that post that Sinestro linked for more details.

I'm not the biggest fan of Django for multiple reasons but it's not outstandingly bad. It's not PHP.

I've never used Ruby on Rails, or Ruby, so I can't give a trip report about that, but it doesn't look that insane.

qntm
Jun 17, 2009
So our testing framework is designed to be able test multiple versions of the same product. Today we're testing v5.0, but tomorrow we might be testing v5.1 or v4.0 (still supported with occasional fixes) using the same framework. But v5.0 has new functionality and needs to be treated a little differently. So:

code:
# set up for a v5 test
if($productVer == $v5point0) {
    ...
}

# set up for v4 or earlier test
else {
    ...
}
:v:

senrath
Nov 4, 2009

Look Professor, a destruct switch!



I really like how the one PHP developer seems to think that we should care more about Rasmus's opinion because he created PHP.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

qntm posted:

So our testing framework is designed to be able test multiple versions of the same product. Today we're testing v5.0, but tomorrow we might be testing v5.1 or v4.0 (still supported with occasional fixes) using the same framework. But v5.0 has new functionality and needs to be treated a little differently. So:

code:
# set up for a v5 test
if($productVer == $v5point0) {
    ...
}

# set up for v4 or earlier test
else {
    ...
}
:v:

That's god-awful. Why aren't you unit testing with a real framework that runs as part of your CI process? Why don't you have a CI process? Why aren't you branching your code for each release so you can test each release in isolation? Why do you work there?

Seriously, the more I think about this, the more it hurts my head. If you're supporting multiple versions of an application, you're being straight-up retarded by not branching your code and maintaining those different versions independently.

New Yorp New Yorp fucked around with this message at 18:03 on Jun 22, 2012

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Zombywuf posted:

"Document" and "key-value" databases are the real horror.

Care to explain? memcached is a perfectly find KV store, as are Cassandra and Redis.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Does anybody even use Cassandra anymore?

Johnny Cache Hit
Oct 17, 2011

Sinestro posted:

Do not pick Python for web development. It is a pretty great language, but Django is a enormous piece of poo poo that breaks if you cough on it too hard. Pick Ruby, which is a great language with great support for all sorts of expressive new ways to write code, and gives you Rails, which makes web development so much nicer.

I've done a ton of work with Django at my last job and found it to be a solid framework until you push it too hard. But I think this is a bit of an overstatement. Feel free to pick from one of the many other Python frameworks - I'm a big Flask fan, and even prefer it over Django.

But saying "don't pick Python" because you don't like Django is tremendously stupid, please don't do that, thanks.

Suspicious Dish posted:

Does anybody even use Cassandra anymore?

I think most people ran screaming from Cassandra a long time ago.

And I'm not sure why Zombywuf dislikes document databases or KV stores, but I'm not a fan because I've worked on far too many projects built on a document database just to be built on a document database.

qntm
Jun 17, 2009

Ithaqua posted:

That's god-awful. Why aren't you unit testing with a real framework that runs as part of your CI process? Why don't you have a CI process? Why aren't you branching your code for each release so you can test each release in isolation? Why do you work there?

Seriously, the more I think about this, the more it hurts my head. If you're supporting multiple versions of an application, you're being straight-up retarded by not branching your code and maintaining those different versions independently.

I forgot a piece of information. We branch the test material for each major release, but this is for migration testing between versions.

Oh, and also perhaps I was misleading:

code:
# set up for a v5 test
if($productVer == $v5point0) {
    ...
}

# set up for v4 or earlier test
else {
    ...
}

# actual testing happens here

Zombywuf
Mar 29, 2008

trex eaterofcadrs posted:

Care to explain? memcached is a perfectly find KV store, as are Cassandra and Redis.

Memcached is a HTML template cache node. Cassandra is, that thing, you know, I think it has something to do with Facebook, not sure if they still use it, it's for, something or other. The last time I checked there were some basic management features that required you shut down the whole cluster. Redis is memcached with some bells and whistles. Half these things sound like someone went through a database book picked some words at random and went "Yeah, we'll implement those."

I rarely see any justification for using them beyond "We done hosed up our architecture and we need something to patch over the holes with."

Zombywuf
Mar 29, 2008

Kim Jong III posted:

And I'm not sure why Zombywuf dislikes document databases or KV stores, but I'm not a fan because I've worked on far too many projects built on a document database just to be built on a document database.

This is pretty much the whole reason. Plus I've found document databases to be slow in any stress test I've put them under.

silvergoose
Mar 18, 2006

IT IS SAID THE TEARS OF THE BWEENIX CAN HEAL ALL WOUNDS




Zombywuf posted:

Memcached is a HTML template cache node. Cassandra is, that thing, you know, I think it has something to do with Facebook, not sure if they still use it, it's for, something or other. The last time I checked there were some basic management features that required you shut down the whole cluster. Redis is memcached with some bells and whistles. Half these things sound like someone went through a database book picked some words at random and went "Yeah, we'll implement those."

I rarely see any justification for using them beyond "We done hosed up our architecture and we need something to patch over the holes with."

Wait, what? What do you mean by HTML template cache node? I've only seen memcached used as a cache for something held in memory that needs to be flushed from multiple (read: distributed) sources.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Zombywuf posted:

Memcached is a HTML template cache node. Cassandra is, that thing, you know, I think it has something to do with Facebook, not sure if they still use it, it's for, something or other. The last time I checked there were some basic management features that required you shut down the whole cluster. Redis is memcached with some bells and whistles. Half these things sound like someone went through a database book picked some words at random and went "Yeah, we'll implement those."

I rarely see any justification for using them beyond "We done hosed up our architecture and we need something to patch over the holes with."

Seems like you're glossing over a whole class of databases with some hand-wavy "well, I think they do this". Sometimes you just need to put stuff into a database with a simple key. Building that on a relational database is using the wrong tool for the job.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Zombywuf posted:

Memcached is a HTML template cache node. Cassandra is, that thing, you know, I think it has something to do with Facebook, not sure if they still use it, it's for, something or other. The last time I checked there were some basic management features that required you shut down the whole cluster. Redis is memcached with some bells and whistles. Half these things sound like someone went through a database book picked some words at random and went "Yeah, we'll implement those."

I rarely see any justification for using them beyond "We done hosed up our architecture and we need something to patch over the holes with."

You dislike them because you don't know what they are?

Look Around You
Jan 19, 2009

Golbez posted:

Web development. Currently rocking PHP/MySQL, and have been wondering about finding a better alternative to MySQL as well.

You pretty much can't go wrong with Ruby or Python. They both have large frameworks that they're known for (Rails for Ruby, Django for Python) and lighter frameworks for more flexible development (Sinatra for Ruby, Flask and Pyramid for Python).

As for the differences between the languages... Ruby is very good at writing DSLs and gives you a lot of opportunity for "natural" looking language extensions. It's big on giving you a lot of ways to do things (which is a key part of its philosophy, taken from Perl). It's mostly constrained to web development though; I can't really think of many non-web libraries for it.

Python on the other hand values a standard syntax and a standard way of doing things. In their opinion there should be one "best" way to do things, which should be clean, easy and obvious; you'll hear this referred to as the "Pythonic" way of doing something. Python has branched out beyond web development though; SciPy (with NumPy) are a great option for scientific computing and there are (were?) game development libraries, but I don't remember which are defunct.

One more thing about Python: there's two main versions, Python 2 and Python 3. Python 2 is still the most commonly used version as python 3 introduced some backwards incompatible changes and not all libraries have updated to py3 yet.

Johnny Cache Hit
Oct 17, 2011

trex eaterofcadrs posted:

Seems like you're glossing over a whole class of databases with some hand-wavy "well, I think they do this". Sometimes you just need to put stuff into a database with a simple key. Building that on a relational database is using the wrong tool for the job.

Personally, I've yet to convince myself that most programmers know when it's actually a good idea to use a non-relational database, and how to use one without introducing far more problems into their system.

An illustrative horror in two parts: One place I worked at wanted to use CouchDB but didn't like the whole "views, not queries" thing so they were going to funnel everything through elasticsearch as well. That way "searches could be done against elasticsearch, and we don't have to make a ton of CouchDB views" :v:

het
Nov 14, 2002

A dark black past
is my most valued
possession

Look Around You posted:

As for the differences between the languages... Ruby is very good at writing DSLs and gives you a lot of opportunity for "natural" looking language extensions. It's big on giving you a lot of ways to do things (which is a key part of its philosophy, taken from Perl). It's mostly constrained to web development though; I can't really think of many non-web libraries for it.
This really isn't true, we've been steadily moving from Perl to Ruby for most of our systems programming at my workplace. On its own, ruby's selection of libraries isn't bad, and they certainly aren't exclusively web-specific; for instance, we've been using EventMachine and protobufs a fair bit for general network programming. On top of that, if you use jruby, you can get access to Java implementations of just about anything you can imagine.

tef
May 30, 2004

-> some l-system crap ->

Zombywuf posted:

Memcached is a HTML template cache node.

Actually memcache was written because mysql couldn't cache queries well.

Doctor w-rw-rw-
Jun 24, 2008

Zombywuf posted:

Memcached is a HTML template cache node.

Yeah...no. I would expect nothing less from the Coding horrors thread. If this is really how you use memcached then I hope you have a good alternative answer for data caching.

Zombywuf posted:

Cassandra is, that thing, you know, I think it has something to do with Facebook, not sure if they still use it, it's for, something or other. The last time I checked there were some basic management features that required you shut down the whole cluster. Redis is memcached with some bells and whistles. Half these things sound like someone went through a database book picked some words at random and went "Yeah, we'll implement those."

I rarely see any justification for using them beyond "We done hosed up our architecture and we need something to patch over the holes with."
Facebook switched to HBase. Cassandra is used more outside than inside. The fact that you rarely see any justification makes you sound like a narrow-minded engineer with little in the way of imagination. Job queues, transient activity feeds, optimization for data analysis - when dealing with large amounts of data, the data storage *does* make a difference.

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
Ruby will turn you into an expert on package management. I set out to learn rails on my own and after exploring super basic out of the box tutorials I tried to add in some common resources I saw on github and so on. Quickly I was in Aptitude/RVM/Git/Gem hell for a while where random .rb files would error out whenever I tried to Rake. It was probably mostly due to being an impatient noob at it but it definitely soured the experience. By the time I got it all working I just wanted to move on to something else entirely.

That being said I think the big culprit was me putting too much faith into aptitude. All the mini package managers within the Ruby domain seemed to stay in-step and once I completely uninstalled everything out of aptitude and learned to let RVM do all the driving things started to work themselves out.

tef
May 30, 2004

-> some l-system crap ->

Look Around You posted:

You pretty much can't go wrong with Ruby or Python. They both have large frameworks that they're known for (Rails for Ruby, Django for Python) and lighter frameworks for more flexible development (Sinatra for Ruby, Flask and Pyramid for Python).

I'd wager that ruby is easier to pick up for php developers than python, or perhaps, ruby is easier to write php in than python is - python has immutable strings, explicit self, an explicit unicode type, and semantic whitespace.

quote:

As for the differences between the languages... Ruby is very good at writing DSLs and gives you a lot of opportunity for "natural" looking language extensions. It's big on giving you a lot of ways to do things (which is a key part of its philosophy, taken from Perl).

To be obsequious, ruby reminds me of a lisp-2 with a smalltalk semantics and perl syntax :3:

quote:

One more thing about Python: there's two main versions, Python 2 and Python 3. Python 2 is still the most commonly used version as python 3 introduced some backwards incompatible changes and not all libraries have updated to py3 yet.

Ruby similarly has some issues between 1.8 and 1.9 with the introduction of unicode handling.

etcetera08
Sep 11, 2008

tef posted:

To be obsequious, ruby reminds me of a lisp-2 with a smalltalk semantics and perl syntax :3:

perl + ada syntax :3:

After spending a year or so learning programming with mostly Python and some Java, I've found Ruby to be a really nice language. I think I prefer it to Python at this point, although I haven't spent as much time with it.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
I really, really like Ruby and use it a lot; it's clear, it does a really good job of sticking to its paradigm, and the warts it has haven't really blown my face off PHP-style.

But I think Clojure has won over my blackened heart. Holy poo poo do I love 'seq

Zombywuf
Mar 29, 2008

Doctor w-rw-rw- posted:

Yeah...no. I would expect nothing less from the Coding horrors thread. If this is really how you use memcached then I hope you have a good alternative answer for data caching.
I don't use memcached these days. Last time I did I used it as a db cache. Turns out the db didn't need caching and I should have told the people pestering me about caching to go gently caress themselves. All it did was add complexity and it could go for weeks with memcached down and no-one noticed, turns out my time was best spent making the db fast, which it was.

quote:

Facebook switched to HBase. Cassandra is used more outside than inside. The fact that you rarely see any justification makes you sound like a narrow-minded engineer with little in the way of imagination. Job queues, transient activity feeds, optimization for data analysis - when dealing with large amounts of data, the data storage *does* make a difference.
You're quite right, the data storage *does* make a difference. Tell me, how do you implement a star schema in Redis? Normalise HBase for data size minimisation? Cluster data in Cassandra to maximise temporal and cache locality? Organise data access patterns in memcache to minimise contention while maintaining some degree of transactional integrity?

Please don't claim you don't need to do these things unless you can provide me with a stack of benchmarks.

ps. have you considered using a message queue for queuing? Just a thought.

Zombywuf fucked around with this message at 20:46 on Jun 22, 2012

ErikTheRed
Mar 12, 2007

My name is Deckard Cain and I've come on out to greet ya, so sit your ass and listen or I'm gonna have to beat ya.
Oh man, I don't even know what to say here

code:
public static String moveDecimal(String pValue, int pBy)
{
	String lZeros = "00000000000000000000000000000";
	int lFoundAt;
	int lDecimalLength = 0;
	String lValue = null;
	lFoundAt = pValue.indexOf(".");
	if (lFoundAt >= 0)
		lDecimalLength = pValue.length() - lFoundAt - 1;
	if (lFoundAt > 0)
		lValue = pValue.substring(0, lFoundAt);
	else
		lValue = "";
	if (lDecimalLength > pBy && lDecimalLength > 0)
	{
		lValue += pValue.substring(lFoundAt + 1, lFoundAt + pBy + 1) + "." + pValue.substring(lFoundAt + pBy + 1);
	}
	else if (lDecimalLength == pBy && lDecimalLength > 0)
	{
		lValue += pValue.substring(lFoundAt + 1, lFoundAt + pBy + 1);
	}
	else if (lDecimalLength < pBy && lDecimalLength > 0)
	{
		lValue += pValue.substring(lFoundAt + 1);
		lValue += lZeros.substring(0, pBy - lDecimalLength);
	}
	else if (lDecimalLength == 0)
	{
		if (lFoundAt < 0) lValue = pValue;
		lValue = lValue + lZeros.substring(0, pBy);
	}
	return lValue;
}

Adbot
ADBOT LOVES YOU

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Golbez posted:

Web development. Currently rocking PHP/MySQL, and have been wondering about finding a better alternative to MySQL as well.

You guys are going to laugh, but I've been pleasantly surprised by .NET's evolution over the last few years. Just throwin that out there.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply