Yii Framework Forum: Backward Compatibility Questions - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Backward Compatibility Questions

#1 User is offline   Jaggi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 05-September 11

Posted 09 May 2013 - 11:08 AM

Just been looking at the following article and had a few question as to why a few things are why they are which breaks backwards compatibility and some in what seems like needlessly.

https://github.com/y...rade-from-v1.md

Quote

The render() and renderPartial() methods now return the rendering results instead of directly sending them out. You have to echo them explicitly, e.g., echo $this->render(...);.



Why does the render method work in this way, the way it worked before was fine and if someone wanted to return the output there was an option to return the output if needed. I quite liked not having any echos in my controllers.

Quote

Yii::t('yii|message to be translated').


this seems a little pointless it opens up more options for errors as the syntax has become more complicated (i'm sure theres some people who don't know where pipe is on the keyboard...??). Having it take two separate params was easier to interpret, broke the method if not done right (which is preferred as now it introduces a silent error (maybe, need to look at the method?)). I've also in the past overloaded this method and used the category field to do certain checks in certain instances which now has added an extra step.

I would prefer if this method at least supported both methods. Also Yii::t() is probably one of the most common methods in any large translated site and having to update all these methods is a pain if updating a project from 1.1.
See my development site @ www.CodeTheInter.net (BETA)

Posted Image Posted Image

Quote

If you make it idiot proof, they'll build a better idiot
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,697
  • Joined: 04-March 10
  • Location:UK

Posted 10 May 2013 - 03:10 AM

Yii 2 is a completely different code base, redesigned from the ground up. The developers are aiming to create the best framework that they can rather than maintain maximum backwards compatibility.

You don't need to upgrade old sites to Yii 2, the Yii 1.1.x branch will remain stable.

In answer to your question, I expect that the rendering has changed to prevent the code divergence caused by accepting a boolean parameter which either outputs or returns a string. I'm not sure about the changes to translation as it's something I've not yet needed to use.

In essence, any changes are likely to be intended to produce more elegant and maintainable code. Backwards compatibility won't be the main concern because people don't need to upgrade old projects; this is a completely new framework version.
3

#3 User is offline   Jaggi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 05-September 11

Posted 10 May 2013 - 03:41 AM

View PostKeith, on 10 May 2013 - 03:10 AM, said:

Yii 2 is a completely different code base, redesigned from the ground up. The developers are aiming to create the best framework that they can rather than maintain maximum backwards compatibility.

You don't need to upgrade old sites to Yii 2, the Yii 1.1.x branch will remain stable.

In answer to your question, I expect that the rendering has changed to prevent the code divergence caused by accepting a boolean parameter which either outputs or returns a string. I'm not sure about the changes to translation as it's something I've not yet needed to use.

In essence, any changes are likely to be intended to produce more elegant and maintainable code. Backwards compatibility won't be the main concern because people don't need to upgrade old projects; this is a completely new framework version.


I completely disagree with this. Just because its new major version it makes no sense that someone will not be upgrading any existing applications. This is just bad practice and when 1.1 reached EOL then you're left with a web application that which will be on unsupported software (mysql/php) and will no longer have security updates. Our web applications aren't standard blogs or general sites, these are enterprise web applications in the truest sense and maintenance and development on these applications are ongoing.

Yii 2 also isn't a completely different code base, yes a lot has been redeveloped and restructured but parts of 1.1 still exist (yii::t() / render for example). We know a lot of code will break in the 2.0 upgrades and I'm not disputing that just wondering why certain things have been changed when they don't necessarily need to be. Just because yii have said they're not going to maintain backwards compatibility doesn't mean you need to take a hammer to everything.
See my development site @ www.CodeTheInter.net (BETA)

Posted Image Posted Image

Quote

If you make it idiot proof, they'll build a better idiot
0

#4 User is offline   twisted1919 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 652
  • Joined: 23-October 10
  • Location:Romania

Posted 10 May 2013 - 05:11 AM

Personally i don't care if Yii2 breaks BC, neither you should(we really need to move forward with Yii).
Why?
Because Yii 1.1 branch is stable and can be used years from now on, and it will also be supported by the Yii team for a period of time after 2.0 is released.

Now, let's assume you have a mighty huge project built on Yii 1 (i do have a lot of them) and in 2015 Yii team decides to drop the support for Yii 1.1.x.
What do you do ?
Well, having in mind that we're talking about a stable branch there might be nothing for you to do, the app already works so if you don't upgrade php or anything else nothing should break(please note i am using Yii 1.1 with php 5.5.0 RC now and it works perfectly).
The only concern is security issues, thing that it should not happen to you if you built yourself a secure app (yii already offers all the tools you need to accomplish this).

Bottom line is, you can use Yii 1.1 years after it is not supported any more, just deal with it, you are a developer not a designer.

Regarding the other issues you have, with render() and Yii::t() etc, just go to github and ask/make suggestions, etc. I know that we should get a Response Class in Yii 2, so the render method can become just a shorthand to the Response class, things are to be changed in Yii 2 from day to day, if you care about the direction it goes, just get on github and get involved.


Struggling to keep BC with Yii 2 is just unreal and it doesn't cut the effort.
Let's move on with Yii already, we are behind zend/symfony and i don't like this, but i do like the direction Yii 2 goes.
2

#5 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 10 May 2013 - 06:07 AM

I'm with Keith and twisted1919. They both gave good arguments and here I add one more: compromising for backwards compatibility can potentially hinder the progress of the framework.
1

#6 User is offline   Jaggi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 05-September 11

Posted 10 May 2013 - 08:24 AM

View Posttwisted1919, on 10 May 2013 - 05:11 AM, said:

Personally i don't care if Yii2 breaks BC, neither you should(we really need to move forward with Yii).
Why?
Because Yii 1.1 branch is stable and can be used years from now on, and it will also be supported by the Yii team for a period of time after 2.0 is released.

Now, let's assume you have a mighty huge project built on Yii 1 (i do have a lot of them) and in 2015 Yii team decides to drop the support for Yii 1.1.x.
What do you do ?
Well, having in mind that we're talking about a stable branch there might be nothing for you to do, the app already works so if you don't upgrade php or anything else nothing should break(please note i am using Yii 1.1 with php 5.5.0 RC now and it works perfectly).
The only concern is security issues, thing that it should not happen to you if you built yourself a secure app (yii already offers all the tools you need to accomplish this).

Bottom line is, you can use Yii 1.1 years after it is not supported any more, just deal with it, you are a developer not a designer.

Regarding the other issues you have, with render() and Yii::t() etc, just go to github and ask/make suggestions, etc. I know that we should get a Response Class in Yii 2, so the render method can become just a shorthand to the Response class, things are to be changed in Yii 2 from day to day, if you care about the direction it goes, just get on github and get involved.


Struggling to keep BC with Yii 2 is just unreal and it doesn't cut the effort.
Let's move on with Yii already, we are behind zend/symfony and i don't like this, but i do like the direction Yii 2 goes.



View PostRodrigo Coelho, on 10 May 2013 - 06:07 AM, said:

I'm with Keith and twisted1919. They both gave good arguments and here I add one more: compromising for backwards compatibility can potentially hinder the progress of the framework.


I think you're both missing the point here for arguments sake. Resolving those issues will in no way what so ever hinder yii 2.0 going forward. Those changes do not add any extra functionality. I've used BC as a example but the point is if it ain't broke and makes no enhancement then why change it.

Everyone whos replied in this thread so far has failed to realise this and the arguments for continuing to use yii 1 because its a difficult to upgrade is incomprehensible to me and as a developer goes against my way of working. I'm not saying make it easy to upgrade from yii 1 to yii 2. I haven't highlighted dozens of other breaking issues i'm just wondering about these two specific issues which make no sense to me.
See my development site @ www.CodeTheInter.net (BETA)

Posted Image Posted Image

Quote

If you make it idiot proof, they'll build a better idiot
0

#7 User is offline   soso 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 45
  • Joined: 24-February 10

Posted 10 May 2013 - 08:41 AM

Hi all,

I think Jaggi posted 2 questions asking for the reasons of the change in render and Yii::t(). Not that it's a bad thing the changing, just what were the reasons. I don't understand them also. Especially Yii::t() which isn't clear anymore imo.
0

#8 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 10 May 2013 - 08:55 AM

Jaggi, about the changes you highlighted, here's my opinion:

Quote

The render() and renderPartial() methods now return the rendering results instead of directly sending them out. You have to echo them explicitly, e.g., echo $this->render(...);.


I like it. Brings uniformity. Only one echo and it is done.

Quote

Yii::t('yii|message to be translated').


I don't like it. Not because the method signature has changed, but because it brings more string mangling to the framework.
Unless there's a good reason for this, I'd like to see this reverted. Or using arrays, which is better than strings IMHO.
0

#9 User is offline   François Gannaz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 87
  • Joined: 24-November 09

Posted 10 May 2013 - 11:29 AM

View PostJaggi, on 09 May 2013 - 11:08 AM, said:

Why does the render method work in this way, the way it worked before was fine and if someone wanted to return the output there was an option to return the output if needed. I quite liked not having any echos in my controllers.

It's a bad practice to print an output by default instead of returning it. The PHP team made the same mistake a long time ago with some functions like `var_dump()`. When they realized that there were cases where the output should not be displayed, they tried to keep BC so they added an optional parameter. Yii 1 did the same.

Yii 2 prefers a clean and consistent interface, even if it breaks BC with Yii 1. All methods return a value instead of displaying it, whereas Yii 1.1 was not consistent (cf `CHtml::link()`).

It also removes some performance bottlenecks and complex code. In Yii 1.1, the rendering can be returned through "output buffering" (see `ob_start()` and such). But this has many side effects. It was also hard to handle several layers of output buffering, and this caused difficult bugs.


View PostJaggi, on 09 May 2013 - 11:08 AM, said:

I would prefer if this method at least supported both methods. Also Yii::t() is probably one of the most common methods in any large translated site and having to update all these methods is a pain if updating a project from 1.1.

I suppose that this change was for performance reasons, but I'm not sure about this. As for migrating, it should be easy to apply a substitute regexp to every PHP file.

More generally, I believe that migrating an application from Yii 1.1 to Yii 2.0 will be a hard work. The two changes above are not much when most of the model code will have to be rewritten. No more CDataProvider, no `relations()` method, no CDbCriteria, etc.
0

#10 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,640
  • Joined: 10-October 10
  • Location:Denmark

Posted 10 May 2013 - 02:06 PM

Printing instead of returning is bad - that is not good functional programming style: the functions have side-effects. Or, put differently: they do things behind your back.
I do like the change.
If we want it printed, we print the data that we get from the function.
It also makes it easier to chain function calls, concatenate, delay output or send it to another function.
Good programming practice IMO.
"Less noise - more signal"
0

#11 User is offline   soso 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 45
  • Joined: 24-February 10

Posted 10 May 2013 - 03:15 PM

render, makes sense. But what about t()? I can't see any advantage other than obsfucation?
0

#12 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,906
  • Joined: 04-October 08
  • Location:DC, USA

Posted 10 May 2013 - 03:53 PM

The main reason for the Yii::t() change is because I want it easier to use if your category is the default one (which is the case mostly). For example, you can use Yii::t('translate me'). Without this, you have to type Yii::t('app', 'translate me').
0

#13 User is offline   Müller 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 23-June 12
  • Location:Netherlands

Posted 11 May 2013 - 04:09 AM

View Postqiang, on 10 May 2013 - 03:53 PM, said:

The main reason for the Yii::t() change is because I want it easier to use if your category is the default one (which is the case mostly). For example, you can use Yii::t('translate me'). Without this, you have to type Yii::t('app', 'translate me').


I also like it better that you don't have to explicit specify the translation category anymore. But then why not using like @Rodrigo Coelho suggested? If it's a string, use it as the translation, if it's an array(), use the first element as the category and the second as the translation. I think a is_array check is faster than a strpos && preg_match.
2

#14 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 11 May 2013 - 04:53 AM

Qiang, thanks for the clarification!
I agree with Müller's points.

I see two aspects being tackled here:

1) Ease of use.

After reading the documentation for YiiBase:t, I agree with Qiang that it will be easy for app developers to use the method. We simply won't need to pass the category when we're using the default "app" category.

But this simplicity comes at a cost:

  • We will embed functionality in a string. And the the framework will have to check the string for this value.
  • Extension authors won't probably have the same simplicity; they'll need to embed the category inside the string (because I didn't find a way to change the string from the default "app" category for a single Module; it is hardcoded in I18N). Having to specify the category in a module is not a big issue, though (the problem is having to do it inside a string).


2) Embedding functionality in a string.

This is something I didn't like from 1.1. One example in 1.1 occurs in the CActiveRecord::relations method for MANY_MANY relations, where you had to specify multiple parts of the relation in a single string.

In this case, having another method parameter would be ideal, but having an array could be a good compromise, with the benefits of:

  • Providing better documentation.
  • Being extensible (will probably need associative arrays).
  • Possibly being faster than handling strings (no benchmarks were made).


The array would be need only when there's more information to provide than the message string.

The only drawback I can think of is that the code will be more verbose when the array is used.
0

#15 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,861
  • Joined: 17-January 09
  • Location:Russia

Posted 11 May 2013 - 07:15 AM

I like Müller's solution. Qiang, I think it is better than current one.

Pros

- All the pros of current one.
- Better IDE support.
- Less error prone.
- Familiar PHP syntax.

Cons

None?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#16 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,906
  • Joined: 04-October 08
  • Location:DC, USA

Posted 11 May 2013 - 07:23 AM

What is Muller's solution? Use some code examples to explain?
0

#17 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 11 May 2013 - 07:29 AM

The proposed solution would use code like:

// Default category, as it is now:
Yii::t('message');

// Another category, with an array:
Yii::t(array('category', 'message'));


The order of the values (category and message) or if the array should be associative weren't discussed.
0

#18 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 274
  • Joined: 15-March 09

Posted 11 May 2013 - 07:32 AM

Another way would be to make the method variadic. Allow signatures

t( message: string ): string
t( message: string, params: array ): string
t( message: string, params: array, language: string ): string
t( category: string, message: string ): string
t( category: string, message: string, params: array ): string
t( category: string, message: string, params: array, language: string ): string

or simly introduce a method t2.
Don't like ads in my sig...
0

#19 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,906
  • Joined: 04-October 08
  • Location:DC, USA

Posted 11 May 2013 - 07:34 AM

@Ben: thanks. I like both. The t2 approach is slightly better.
0

#20 User is offline   twisted1919 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 652
  • Joined: 23-October 10
  • Location:Romania

Posted 11 May 2013 - 12:49 PM

Wait, what ?
So we should have Yii::t() and Yii::t2() ? Come on...
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users