Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old July 4, 2019, 15:45   #81
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,273
Donated: $40
Pete Mack is on a distinguished road
powerwyrm-
those declrations are all thru the code, not just in sdl2. And the standard is 20 years old, back to C99.
Pete Mack is offline   Reply With Quote
Old July 4, 2019, 15:55   #82
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,923
Donated: $40
takkaria is on a distinguished road
Ah, it's BCC, not MSVC. That is ancient!
__________________
takkaria whispers something about options. -more-
takkaria is offline   Reply With Quote
Old July 4, 2019, 22:22   #83
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 54
Posts: 7,645
Donated: $60
Nick is on a distinguished road
Quote:
Originally Posted by PowerWyrm View Post
Trying to port the SDL2 frontend to PWMAngband at this time.
Any improvements you make to this frontend gratefully received
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
Nick is offline   Reply With Quote
Old July 5, 2019, 02:47   #84
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,273
Donated: $40
Pete Mack is on a distinguished road
Nick--
I am not convinced that going back to archaic C is an improvement. Variable declarations as needed is a whole lot easier to read.
Pete Mack is offline   Reply With Quote
Old July 5, 2019, 08:21   #85
PowerWyrm
Prophet
 
PowerWyrm's Avatar
 
Join Date: Apr 2008
Posts: 2,605
PowerWyrm is on a distinguished road
Quote:
Originally Posted by Pete Mack View Post
Nick--
I am not convinced that going back to archaic C is an improvement. Variable declarations as needed is a whole lot easier to read.
Not really. I'm used to declare my variables at the beginning of functions even when using C++ or Java and I find the code much easier to read that way. But of course I'm an old developer... In my time, RAD environments didn't even exist, you had to code everything. Heck, at my time we were coding using Pascal...
__________________
PWMAngband variant maintainer - check http://powerwyrm.monsite-orange.fr (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!
PowerWyrm is offline   Reply With Quote
Old July 5, 2019, 15:00   #86
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 8,795
Derakon is on a distinguished road
Quote:
Originally Posted by PowerWyrm View Post
Not really. I'm used to declare my variables at the beginning of functions even when using C++ or Java and I find the code much easier to read that way. But of course I'm an old developer... In my time, RAD environments didn't even exist, you had to code everything. Heck, at my time we were coding using Pascal...
There's a lot of reasons why on-the-fly declarations is the standard these days. The biggest one IMO is that it allows you to scope a variable to just the block of code it is used in. For example, in many languages this:
Code:
for (int i = 0; i < 10; ++i) {
  ...
}
means that the `i` variable does not exist outside of that for loop. This is a great way to avoid accidentally using your loop iterator in the wrong context. And if you do need it outside of that context, then it's trivial to explicitly declare it, which is then a signal to the reader that "hey, this loop variable will probably be needed later."
Derakon is offline   Reply With Quote
Old July 5, 2019, 18:06   #87
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,923
Donated: $40
takkaria is on a distinguished road
I guess these days it matters less to me because I tend to write shorter functions than I used to, but in the past I found that putting definitions not at the top of functions was useful for figuring out what was used when. I think Angband is particularly bad in some of its older code for this. You have a 3 page long function with variable names like 'seen' and 'flag' which are defined at the top of a function and used twice somewhere in the middle. It's really difficult to understand what is going on.

Arguably the problem here is that the function is too long and the variables are named badly, rather than that they're not defined as used. But I think Derakon's example of for-scoped variables is the most obviously good use case.

Languages like Elm, F#, Haskell always put their variables at the top of the function. But those are paradigmatically functional languages so it's a lot easier to reason about the code anyway.
__________________
takkaria whispers something about options. -more-
takkaria is offline   Reply With Quote
Old July 5, 2019, 23:38   #88
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 54
Posts: 7,645
Donated: $60
Nick is on a distinguished road
Quote:
Originally Posted by takkaria View Post
I guess these days it matters less to me because I tend to write shorter functions than I used to, but in the past I found that putting definitions not at the top of functions was useful for figuring out what was used when. I think Angband is particularly bad in some of its older code for this. You have a 3 page long function with variable names like 'seen' and 'flag' which are defined at the top of a function and used twice somewhere in the middle. It's really difficult to understand what is going on.
I tend to be with takkaria on this one (not least because most of the C I write is for Angband). I also agree about the length of the functions, with calc_bonuses() and some of the object handling and targeting functions being among the big offenders.

All that said, my comment to PowerWyrm was mainly to encourage the continued finding of bugs in V code. I'm not sure if anyone else has noticed, but the 4.x.y releases where y > 0 are usually heavily loaded with bugfixes provided by PowerWyrm while implementing 4.x.y-1 features into PWMAngband
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
Nick is offline   Reply With Quote
Old July 8, 2019, 08:28   #89
PowerWyrm
Prophet
 
PowerWyrm's Avatar
 
Join Date: Apr 2008
Posts: 2,605
PowerWyrm is on a distinguished road
Unfortunately SDL2 is allergic to BCC for some reasons so I gave up porting SDL2 to PWMAngband. And it seems that you would need at least DX8 which isn't available in the header list of the compiler (SDL1 uses DX5 which seems supported).
__________________
PWMAngband variant maintainer - check http://powerwyrm.monsite-orange.fr (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!
PowerWyrm is offline   Reply With Quote
Reply

Tags
libsdl2


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Android-port not work Angrist Vanilla 1 October 14, 2014 03:24
Web Port wilbur07 Vanilla 6 February 27, 2014 13:39
OpenGL port BreathesFire Development 2 November 3, 2011 07:22
[FA] NDS port Donald Jonker Variants 54 October 6, 2011 15:49
[V] Gtk port Magnate Development 1 February 24, 2009 09:48


All times are GMT +1. The time now is 15:12.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.