lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I am proposing a language sugar =)

Because It's not a simple matter of the file exists or not. 

Think about these 3 real case examples:
- A not gracefully end of the tcp connection can occur.
- if the file is stored in a Pen Drive, the user can unplug the device in the middle of the process or a bad contact in the wires can lead to physical IO errors.
- If the user is connected via an USB Wireless adapter, if the user unplugs the device or a bad contact in the wires occur, physical IO errors can occur.

Many other unexpected situations can occur.

On Tue, May 31, 2016 at 9:11 AM, steve donovan <steve.j.donovan@gmail.com> wrote:
On Tue, May 31, 2016 at 1:39 PM, Alysson Cunha <alyssonrpg@gmail.com> wrote:
> In a simple example of file transfer over the internet, unexpected things
> can occur in the middle of the process and it is a good pratice ensure that
> the "file handle" will be closed at the end no matter what. In these case, a
> try-finally statement would be very useful.

Ah, but we use pcall for that - try/except in Lua would be sugar for that idiom.

Sugar is fine when it does not have any runtime costs (e.g. a:f(b) is
short for a.f(a,b)) but in this case a closure would be silently
constructed.

I tend to side with Jonne here - exceptions are overused. It's easy to
check if a file exists, why throw an exception to be handled dozens of
stack frames down? (--> Java <---)




--
Alysson Cunha / AlyssonRPG
http://www.rrpg.com.br - Jogue o tradicional RPG de mesa online
http://www.alyssoncunha.com.br - Me conheça melhor