Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Why shouldn't I ever use coroutines?

One of the comments on this thread: Checking condition and calling continuous method with periods of delay unity, said that:

Never never ever use coroutines. They teach bad habits from the point of view as a c# developer and will lead to a lynching if you take a regular c# job

My question is, why is this? Is this just in Unity or in general? Unity's official virtual reality samples https://www.assetstore.unity3d.com/en/#!/content/51519 use them very heavily (especially the flyer example) instead of Invoke or Invoke Repeating, these sample projects were released recently as well.

like image 218
Martin Dawson Avatar asked Mar 05 '16 16:03

Martin Dawson


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.


1 Answers

This is very much a Unity thing, though the advice is applicable anywhere.

Developers do not expect iterating an IEnumerable to change a program's state. It's not what IEnumerable is intended for and is an inconsistent behavior with all of .NET.

What Unity is doing is using yield return as a pseudo-coroutine, and it's going to cause confusion for any devs unfamiliar with that.

In modern C# we have async/await to accomplish what Unity intended, but Unity was made before that feature was available.

like image 72
Cory Nelson Avatar answered Nov 14 '22 23:11

Cory Nelson