QUOTE (takerraj @ Nov 6 2009, 12:54 PM)

So, which language is the best and effective. I know its tough to say that this language is best or worst? Every language has its own advantages and disadvantages. But, I am curious to know which language achieves that MAX/MIN principle stated in above comment. Is there any language that can be effectively used for almost any project?
By the way, how many days/months it takes to learn a language (to achieve intermediate stage) personally?
For me, if i was back at school, coding a major project, i would head straight for Ruby, Lua or any other language that lends itself to rapid development. Lets face it, you just do not want to be writing hundreds of lines of support code to get to the point where you start to develop the content part of your program. Take the following snippets for example and tell me which one you would rather code? Both of these functions write to file a player in an MMO style game. The first is in Ruby and the 3nd is in C, In C you have to be careful with how you write stuff to file and it is easy to make a mess of it, in Ruby you call YAML and it deals with it all for you.
Also, think about things like memory management, in C you have to allocate the destroy memory yourself, do it at the wrong time and you seg fault or worse still, you have a memory leak and you use up all the system resources and you take out the OS as well when you crash

. In Ruby you do not have to worry about memory management, and cleaning up is done with a garbage collector.
It took me 2 months to be comfortable working in Ruby, not because it is hard to learn, but rather because i was doing object orientated coding for the first time, and it took me a while to get used to using classes, methods, inheritance and all those neat things you just do not use when you code procedurally. You will learn enough of the syntax to be able to write code in no time at all. The main thing i suggest is to nut out your programs design first, then worry about programming language and then coding it. The latter two will take you next to no time at all if you have a great design.
CODE
def save_player dMob
return if dMob.nil?
File.open(sprintf("players/%s.yml", dMob.name.downcase.capitalize), "w") do |f|
YAML::dump dMob,f
end
rescue
$log.error "Unable to write to %s's pfile", dMob.name
$log.error $!
end
AND:
CODE
void fwrite_char( CHAR_DATA * ch, FILE * fp )
{
AFFECT_DATA *paf;
int sn;
short pos;
SKILLTYPE *skill = NULL;
fprintf( fp, "#PLAYER\n" );
fprintf( fp, "Version %d\n", SAVEVERSION );
fprintf( fp, "Name %s~\n", ch->name );
if( ch->description[0] != STRING_NULL )
fprintf( fp, "Description %s~\n", ch->description );
fprintf( fp, "Sex %d\n", ch->sex );
fprintf( fp, "Class %d\n", ch->Class );
fprintf( fp, "Race %d\n", ch->race );
fprintf( fp, "Languages %d %d\n", ch->speaks, ch->speaking );
fprintf( fp, "Level %d\n", ch->level );
fprintf( fp, "Played %d\n", ch->played + ( int )( current_time - ch->logon ) );
fprintf( fp, "Room %d\n", ( ch->in_room == get_room_index( ROOM_VNUM_LIMBO ) && ch->was_in_room ) ? ch->was_in_room->vnum : ch->in_room->vnum );
fprintf( fp, "HpManaMove %d %d %d %d %d %d\n", ch->hit, ch->max_hit, ch->mana, ch->max_mana, ch->move, ch->max_move );
fprintf( fp, "Gold %d\n", ch->gold );
fprintf( fp, "Exp %d\n", ch->exp );
fprintf( fp, "Height %d\n", ch->height );
fprintf( fp, "Weight %d\n", ch->weight );
if( !xIS_EMPTY( ch->act ) )
fprintf( fp, "Act %s\n", print_bitvector( &ch->act ) );
if( !xIS_EMPTY( ch->affected_by ) )
fprintf( fp, "AffectedBy %s\n", print_bitvector( &ch->affected_by ) );
if( !xIS_EMPTY( ch->no_affected_by ) )
fprintf( fp, "NoAffectedBy %s\n", print_bitvector( &ch->no_affected_by ) );
/*
* Strip off fighting positions & store as
* new style (pos>=100 flags new style in character loading)
*/
pos = ch->position;
pos += 100;
fprintf( fp, "Position %d\n", pos );
fprintf( fp, "Practice %d\n", ch->practice );
fprintf( fp, "SavingThrows %d %d %d %d\n", ch->saving_poison_death, ch->saving_mental, ch->saving_physical, ch->saving_weapons );
fprintf( fp, "Favor %d\n", ch->pcdata->favor );
fprintf( fp, "Balance %d\n", ch->pcdata->balance );
fprintf( fp, "Glory %d\n", ch->pcdata->quest_curr );
fprintf( fp, "MGlory %d\n", ch->pcdata->quest_accum );
fprintf( fp, "Hitroll %d\n", ch->hitroll );
fprintf( fp, "Damroll %d\n", ch->damroll );
fprintf( fp, "Tattoo %ld\n", ch->tattoo );
fprintf( fp, "Armor %d\n", ch->armor );
fprintf( fp, "Remorts %d\n", ch->remorts );
if( ch->wimpy )
fprintf( fp, "Wimpy %d\n", ch->wimpy );
if( ch->deaf )
fprintf( fp, "Deaf %d\n", ch->deaf );
if( ch->pcdata && ch->pcdata->outcast_time )
fprintf( fp, "Outcast_time %ld\n", ch->pcdata->outcast_time );
fprintf( fp, "Password %s~\n", ch->pcdata->pwd );
if( ch->pcdata->rank && ch->pcdata->rank[0] != STRING_NULL )
fprintf( fp, "Rank %s~\n", ch->pcdata->rank );
if( ch->pcdata->bestowments && ch->pcdata->bestowments[0] != STRING_NULL )
fprintf( fp, "Bestowments %s~\n", ch->pcdata->bestowments );
fprintf( fp, "Title %s~\n", ch->pcdata->title );
if( ch->pcdata->homepage && ch->pcdata->homepage[0] != STRING_NULL )
fprintf( fp, "Homepage %s~\n", ch->pcdata->homepage );
if( ch->pcdata->min_snoop )
fprintf( fp, "Minsnoop %d\n", ch->pcdata->min_snoop );
if( ch->pcdata->prompt && *ch->pcdata->prompt )
fprintf( fp, "Prompt %s~\n", ch->pcdata->prompt );
if( ch->pcdata->fprompt && *ch->pcdata->fprompt )
fprintf( fp, "FPrompt %s~\n", ch->pcdata->fprompt );
if( ch->pcdata->pagerlen != 24 )
fprintf( fp, "Pagerlen %d\n", ch->pcdata->pagerlen );
fprintf( fp, "\n" );
/*
* If ch is ignoring players then store those players
*/
{
IGNORE_DATA *temp;
for( temp = ch->pcdata->first_ignored; temp; temp = temp->next )
{
fprintf( fp, "Ignored %s~\n", temp->name );
}
}
if( IS_IMMORTAL( ch ) )
{
if( ch->pcdata->bamfin && ch->pcdata->bamfin[0] != STRING_NULL )
fprintf( fp, "Bamfin %s~\n", ch->pcdata->bamfin );
if( ch->pcdata->bamfout && ch->pcdata->bamfout[0] != STRING_NULL )
fprintf( fp, "Bamfout %s~\n", ch->pcdata->bamfout );
if( ch->trust )
fprintf( fp, "Trust %d\n", ch->trust );
if( ch->pcdata && ch->pcdata->restore_time )
fprintf( fp, "Restore_time %ld\n", ch->pcdata->restore_time );
fprintf( fp, "WizInvis %d\n", ch->pcdata->wizinvis );
if( ch->pcdata->r_range_lo && ch->pcdata->r_range_hi )
fprintf( fp, "RoomRange %d %d\n", ch->pcdata->r_range_lo, ch->pcdata->r_range_hi );
if( ch->pcdata->o_range_lo && ch->pcdata->o_range_hi )
fprintf( fp, "ObjRange %d %d\n", ch->pcdata->o_range_lo, ch->pcdata->o_range_hi );
if( ch->pcdata->m_range_lo && ch->pcdata->m_range_hi )
fprintf( fp, "MobRange %d %d\n", ch->pcdata->m_range_lo, ch->pcdata->m_range_hi );
}
if( ch->pcdata->deity_name && ch->pcdata->deity_name[0] != STRING_NULL )
fprintf( fp, "Deity %s~\n", ch->pcdata->deity_name );
if( ch->pcdata->clan_name && ch->pcdata->clan_name[0] != STRING_NULL )
fprintf( fp, "Clan %s~\n", ch->pcdata->clan_name );
fprintf( fp, "Flags %d\n", ch->pcdata->flags );
if( ch->pcdata->release_date )
fprintf( fp, "Helled %d %s~\n", ( int )ch->pcdata->release_date, ch->pcdata->helled_by );
fprintf( fp, "PKills %d\n", ch->pcdata->pkills );
fprintf( fp, "PDeaths %d\n", ch->pcdata->pdeaths );
if( get_timer( ch, TIMER_PKILLED ) && ( get_timer( ch, TIMER_PKILLED ) > 0 ) )
fprintf( fp, "PTimer %d\n", get_timer( ch, TIMER_PKILLED ) );
fprintf( fp, "MKills %d\n", ch->pcdata->mkills );
fprintf( fp, "MDeaths %d\n", ch->pcdata->mdeaths );
fprintf( fp, "IllegalPK %d\n", ch->pcdata->illegal_pk );
fprintf( fp, "AttrPerm %d %d %d %d \n", ch->perm_str, ch->perm_int, ch->perm_dex, ch->perm_con );
fprintf( fp, "AttrMod %d %d %d %d \n", ch->mod_str, ch->mod_int, ch->mod_dex, ch->mod_con );
if( ch->desc && ch->desc->host )
fprintf( fp, "Site %s\n", ch->desc->host );
else
fprintf( fp, "Site (Link-Dead)\n" );
for( paf = ch->first_affect; paf; paf = paf->next )
{
if( paf->type >= 0 && ( skill = get_skilltype( paf->type ) ) == NULL )
continue;
if( paf->type >= 0 && paf->type < TYPE_PERSONAL )
fprintf( fp, "AffectData '%s' %3d %3d %3d %s\n", skill->name, paf->duration, paf->modifier, paf->location, print_bitvector( &paf->bitvector ) );
else
fprintf( fp, "Affect %3d %3d %3d %3d %s\n", paf->type, paf->duration, paf->modifier, paf->location, print_bitvector( &paf->bitvector ) );
}
fprintf( fp, "Coordinates %d %d %d\n", ch->x, ch->y, ch->map );
if( ch->pcdata->nextquest != 0 )
fprintf( fp, "NextQuest %d\n", ch->pcdata->nextquest );
for( sn = 1; sn < top_sn; sn++ )
{
if( skill_table[sn]->name && ch->pcdata->learned[sn] > 0 )
switch ( skill_table[sn]->type )
{
default:
fprintf( fp, "Skill %d '%s'\n", ch->pcdata->learned[sn], skill_table[sn]->name );
break;
case SKILL_SPELL:
fprintf( fp, "Spell %d '%s'\n", ch->pcdata->learned[sn], skill_table[sn]->name );
break;
case SKILL_WEAPON:
fprintf( fp, "Weapon %d '%s'\n", ch->pcdata->learned[sn], skill_table[sn]->name );
break;
case SKILL_TONGUE:
fprintf( fp, "Tongue %d '%s'\n", ch->pcdata->learned[sn], skill_table[sn]->name );
break;
}
}
fprintf( fp, "End\n\n" );
return;
}
Comment/Reply (w/o sign-up)