• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
JohnnyCode

programming language feature idea

13 posts in this topic

Hi,

 

I got an idea about code language idea and it fascinates me, so I would be happy to share it and get critics since I think it is a reasonable feature.

C was a language that promissed runtime variables allocations, as opposed to Pascal. Leading noob programmers to pit of despair. but utilizing a rather fast and absolute control over RAM. Java and C# took some hidden managment of this practice to save programmer and production from ML bugs. Those two languages also eased function definition. And this is my idea -"Inline Function Definition".

Many times I was dived in a large function full of code and I decided I need a function, precisely for the scope of the function I was in, or the class I was in. For example 

public void Instructions()
{
.
.
.
string thelogiclyvarying="constblaconstblacnsta"+ id+"ocnstbla"+onto+"asfloaksf"+wouldlike+"constbla"; /* those variables on right side do not exist and exist and vary in cycle */
//so I would do
public string Compose(string id, string onto,string wouldlike)
{
return "constblaconstblacnsta"+ id+"ocnstbla"+onto+"asfloaksf"+wouldlike+"constbla"; 
}
while (sqlreader.Read())
{
m_sContent+=Compose(sqlreader["odID"],sqlreader["ontorequest"],sqlreader["wouldlike"]);
}
}

You could say I could just write the line- defintion of the function, to the cycle, but I am using this string in more places of the code, plus, if you got habit of doing it, you could clear the code much, plus the coding enviroment could hide the definitions or such.

 

So would you want this compiler feature?

Would it lead to mess or is it against code writing culture?

0

Share this post


Link to post
Share on other sites
perhaps i misunderstand, but isn't this what lambda's do? Edited by slicer4ever
0

Share this post


Link to post
Share on other sites

great, thanks! what a shame it is not featured in C#, anonymous methods seem too inpractic for me.

 

How is an anonymous method too impractical? Isn't it exactly what you described?

0

Share this post


Link to post
Share on other sites
You mean like this?
var m_sContent = string.Join("\n", sqlreader.Select(x => Compose(x.odID, x.ontorequest, x.wouldLike)));
Or this?
var m_sContent = string.Join("\n", sqlreader.Select(x => string.Format("constblaconstblacnsta{0}ocnstbla{1}asfloaksf{2}constbla", x.odId, x.ontorequest, x.wouldLike)));
Or this?
Func<dynamic,string> compose = x => string.Format("{0} {1} {2}", x.odId, x.ontorequest, x.wouldLike));
var m_sContent = string.Join("\n", sqlreader.Select(compose));
Seriously. C# has got you covered. Edited by Nypyren
0

Share this post


Link to post
Share on other sites

You mean like this?
 

 

var m_sContent = string.Join("\n", sqlreader.Select(x => Compose(x.odID, x.ontorequest, x.wouldLike)));

//Or this?

var m_sContent = string.Join("\n", sqlreader.Select(x => string.Format("constblaconstblacnsta{0}ocnstbla{1}asfloaksf{2}constbla", 
               x.odId, x.ontorequest, x.wouldLike)));

//Or this?

Func<SQLElement,string> compose = x => string.Format("{0} {1} {2}", x.odId, x.ontorequest, x.wouldLike));
var m_sContent = string.Join("\n", sqlreader.Select(compose));
 

 




Seriously. C# has got you covered.

Edited by Alpha_ProgDes
0

Share this post


Link to post
Share on other sites
Yup, C# already has those, as others have mentioned. Nypyren has posted some decent idomatic solutions, but I'll give a more "direct" translation from your posted code to real C# code (assuming I don't make a mistake):
public void Instructions()
{
    string thelogiclyvarying="constblaconstblacnsta"+ id+"ocnstbla"+onto+"asfloaksf"+wouldlike+"constbla"; /* those variables on right side do not exist and exist and vary in cycle */
    // And all the magic happens in the next line...
   Func<string, string, string, string> compose = (id, onto, wouldlike) =>
   {
      return "constblaconstblacnsta"+ id+"ocnstbla"+onto+"asfloaksf"+wouldlike+"constbla"; 
   }

   while (sqlreader.Read())
   {
      m_sContent += compose(sqlreader["odID"],sqlreader["ontorequest"],sqlreader["wouldlike"]);
   }
}
Other languages have lambda functions too. C++, C#, every functional language, etc.
0

Share this post


Link to post
Share on other sites

Lambda is what we get in C++11, and aside from the somewhat odd syntax it does everything you're asking. In Pre-C++11 days you could accomplish the same by nesting a functor class, although the generally-large amount of boiler-plate code needed to do so was such that it was often impractical--works exactly the same though, I once had to backport some early C++11 code to a compiler that didn't support lambda syntax, so I became quite familiar with that boilerplate unfortunately.

 

I'd like to have plain old local functions though, and lots of languages have them (D is the only C-like language with direct support). Its not even that they're all that useful--most of the places you'd use them you want a lambda anyway--its more a matter of orthogonality to me, and of giving programmers the means to manage scope and such as they see fit.

0

Share this post


Link to post
Share on other sites

Lambda is what we get in C++11, and aside from the somewhat odd syntax it does everything you're asking. In Pre-C++11 days you could accomplish the same by nesting a functor class, although the generally-large amount of boiler-plate code needed to do so was such that it was often impractical--works exactly the same though, I once had to backport some early C++11 code to a compiler that didn't support lambda syntax, so I became quite familiar with that boilerplate unfortunately.

 

I'd like to have plain old local functions though, and lots of languages have them (D is the only C-like language with direct support). Its not even that they're all that useful--most of the places you'd use them you want a lambda anyway--its more a matter of orthogonality to me, and of giving programmers the means to manage scope and such as they see fit.

 

C++11 lambda does, of course, have its slightly funky syntax and semantics though, though it has been done worse... (*cough* Java *cough*).

granted, I suspect the absence of GC may play into this some (as well as keeping it parsable).

 

as for lambda vs nested functions:

for a lot of languages where lambdas are supported, the compiler is smart enough at least to generally figure out where a cheaper (non-closure) nested-functions can be used instead.

 

or, if you mean the ability to declare nested functions like normal functions/methods (vs having to use a variable and store a lambda into it), then yes, this is a useful feature.

0

Share this post


Link to post
Share on other sites

You mean like this?

var m_sContent = string.Join("\n", sqlreader.Select(x => Compose(x.odID, x.ontorequest, x.wouldLike)));
Or this?
var m_sContent = string.Join("\n", sqlreader.Select(x => string.Format("constblaconstblacnsta{0}ocnstbla{1}asfloaksf{2}constbla", x.odId, x.ontorequest, x.wouldLike)));
Or this?
Func<dynamic,string> compose = x => string.Format("{0} {1} {2}", x.odId, x.ontorequest, x.wouldLike));
var m_sContent = string.Join("\n", sqlreader.Select(compose));
Seriously. C# has got you covered.

Thanks, but it seems too unreadable to me, and my production leaders would not be happy about this habit, plus, I myself am not quite getting it, I think I am getting old :(. Also, the last example seems to be a rather instance of function that gets disposed out of the block, if I am not mistaken, I would rather have possibility to immediately define a function in the scope of the class, so it would not be:
 redefintiion able, instance utilized... and so on. Thanks, it seems that this practice is not very common upon programers, and it did not get maintained to level of effective and reasonable usage .

0

Share this post


Link to post
Share on other sites

Thanks, but it seems too unreadable to me, and my production leaders would not be happy about this habit, plus, I myself am not quite getting it, I think I am getting old sad.png. Also, the last example seems to be a rather instance of function that gets disposed out of the block, if I am not mistaken, I would rather have possibility to immediately define a function in the scope of the class, so it would not be:

 redefintiion able, instance utilized... and so on. Thanks, it seems that this practice is not very common upon programers, and it did not get maintained to level of effective and reasonable usage .

 

It's actually quite common with modern C# programmers. I use lambda's quite frequently. 

0

Share this post


Link to post
Share on other sites

lambdas like those are increadibly common already, and gaining steam. I would also suggest that any 'production leaders' affraid of a little new syntactic sugar every now and then ought to go back amongst the dinosours and take their stone-age coding practices with them. Lambdas are not just modern fluff, or an odd way of defining functions, they enable one to write the kind of code we always meant to but never did before because it was too verbose.

 

Anyway, what's the advantage your hypothetical but non-existant approach holds over the new-to-you but here-today one?

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0