C # Why shouldn't I use coroutines?

One of the comments on this topic: Checking the state and calling the continuous method with unit delay periods , said that:

Never ever use coroutines. They teach bad habits from the point of view of the C # developer and lead to lynching if you do normal C # work

My question is: why is this? Is it only in Unity or in general? Official Unity virtual reality samples https://www.assetstore.unity3d.com/en/#!/content/51519 use them very much (especially the flyer example) instead of Invoke or Invoke Repeating, these sample projects have been released recently.

+5
source share
1 answer

This is the only thing, although the advice applies anywhere.

Developers do not expect the IEnumerable iteration to change the state of the program. This is not what IEnumerable intended for and is inconsistent behavior with all .NET.

What Unity does is use yield return as a pseudo-coroutine, and this will cause confusion for any developers unfamiliar with this.

In modern C #, we have async / await to accomplish what Unity intended, but Unity was done before this function was available.

+7
source

Source: https://habr.com/ru/post/1244489/


All Articles