Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Prelates, Moderators General

Re: Coding: Fleeting Thoughts

Postby Dason » Mon Jan 30, 2012 4:49 am UTC

Are there any major advantages of 3 over 2 that might persuade somebody to use 3 instead?
double epsilon = -.0000001;
User avatar
Dason
 
Posts: 1293
Joined: Wed Dec 02, 2009 7:06 am UTC
Location: ~/

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Mon Jan 30, 2012 5:18 am UTC

Dason wrote:Are there any major advantages of 3 over 2 that might persuade somebody to use 3 instead?


The biggest one is probably all string stuff being Unicode by default, which is good.

The "nonlocal" keyword is also occasionally handy.

Extended iterable unpacking (first, *variable, last = foo).

Set literals; dictionary comprehensions.
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!
User avatar
Aaeriele
 
Posts: 2107
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby RoadieRich » Mon Jan 30, 2012 11:03 am UTC

Aaeriele wrote:...dictionary comprehensions.

2.7 has them.
roband wrote:Mav is a cow.

UniJam 2012: Inter-university Games Jam hosted by Nottingham Trent University DevSoc.
nlug: Nottingham Linux User Group
DevSoc: The Nottingham Trent University Software Development Society
User avatar
RoadieRich
The Black Hand
 
Posts: 1030
Joined: Tue Feb 12, 2008 11:40 am UTC
Location: Somewhere only we know

Re: Coding: Fleeting Thoughts

Postby troyp » Mon Jan 30, 2012 1:15 pm UTC

RoadieRich wrote:
Aaeriele wrote:...dictionary comprehensions.

2.7 has them.

Hey, cool! I didn't know that.
2.7 has set literals, as well, btw.
troyp
 
Posts: 529
Joined: Thu May 22, 2008 9:20 pm UTC
Location: Lismore, NSW

Re: Coding: Fleeting Thoughts

Postby EvanED » Mon Jan 30, 2012 6:28 pm UTC

Some of the stuff I like are the newfound inability to set True and False, and also the fact that things like strings and integers are not orderded between them. (Compare the result of 1 < "hi" in each. In Python 2, this returns true; in Python 3, it throws a TypeError, like a reasonable language.)
EvanED
 
Posts: 4141
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Coding: Fleeting Thoughts

Postby Xeio » Mon Jan 30, 2012 8:15 pm UTC

EvanED wrote:Some of the stuff I like are the newfound inability to set True and False
But then you can't do nonsense like this!
Code: Select all
typeof(string).GetField("Empty").SetValue(null, " ");
User avatar
Xeio
Friends, Faidites, Countrymen
 
Posts: 4805
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Wed Feb 01, 2012 7:31 am UTC

troyp wrote:
RoadieRich wrote:
Aaeriele wrote:...dictionary comprehensions.

2.7 has them.

Hey, cool! I didn't know that.
2.7 has set literals, as well, btw.


Yeah, those are Python 3 features that were backported to the 2.x series (Note that Python 3.0 was actually released 2 years before Python 2.7...).

http://www.python.org/getit/releases/2.7/

Also note that Python 2.7 is the last major release of the 2.x line... so the biggest "feature" that 3.x has is that it's what will be receiving all new versions from here on out.
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!
User avatar
Aaeriele
 
Posts: 2107
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby MHD » Thu Feb 02, 2012 5:18 pm UTC

Has anyone looked at D?
It's like C++, but without all the bad things.
EvanED wrote:be aware that when most people say "regular expression" they really mean "something that is almost, but not quite, entirely unlike a regular expression"
User avatar
MHD
 
Posts: 631
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

Re: Coding: Fleeting Thoughts

Postby Jplus » Thu Feb 02, 2012 6:50 pm UTC

It's been mentioned several times on these forums.
It does miss some of the bad things of C++, but I think in exchange it's also missing some of the good things. It also doesn't seem to add anything spectacular you couldn't have in C++ some way or another. So until somebody can point out such a thing to me, I'm not enthousiast.

(Off-topic: if that was bad English, anyone please send me a PM...)
Feel free to call me Julian. J+ is just an abbreviation.
Image coding and xkcd combined
User avatar
Jplus
 
Posts: 1558
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: classified

Re: Coding: Fleeting Thoughts

Postby RoadieRich » Wed Feb 08, 2012 5:32 pm UTC

Is it just me, or are the streams on sockets in Java backwards?
roband wrote:Mav is a cow.

UniJam 2012: Inter-university Games Jam hosted by Nottingham Trent University DevSoc.
nlug: Nottingham Linux User Group
DevSoc: The Nottingham Trent University Software Development Society
User avatar
RoadieRich
The Black Hand
 
Posts: 1030
Joined: Tue Feb 12, 2008 11:40 am UTC
Location: Somewhere only we know

Re: Coding: Fleeting Thoughts

Postby Xeio » Wed Feb 08, 2012 5:42 pm UTC

Well, I guess you get input from the stream... but yea, I much prefer the Read stream/Write stream idiom.
User avatar
Xeio
Friends, Faidites, Countrymen
 
Posts: 4805
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\

Re: Coding: Fleeting Thoughts

Postby phlip » Wed Feb 08, 2012 9:56 pm UTC

RoadieRich wrote:Is it just me, or are the streams on sockets in Java backwards?

Yeah, the "input stream" is the stream your program gets input from, not the one the socket gets input from.
While no one overhear you quickly tell me not cow cow.
but how about watch phone?
User avatar
phlip
Restorer of Worlds
 
Posts: 7183
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia

Re: Coding: Fleeting Thoughts

Postby Pepve » Wed Feb 08, 2012 11:17 pm UTC

Is it backwards? My OS calls them stdin and stdout..
Pepve
 
Posts: 57
Joined: Wed Jul 28, 2010 9:47 am UTC

Re: Coding: Fleeting Thoughts

Postby MHD » Thu Feb 09, 2012 4:50 pm UTC

Jplus wrote:It's been mentioned several times on these forums.
It does miss some of the bad things of C++, but I think in exchange it's also missing some of the good things. It also doesn't seem to add anything spectacular you couldn't have in C++ some way or another. So until somebody can point out such a thing to me, I'm not enthousiast.

(Off-topic: if that was bad English, anyone please send me a PM...)


It has builtin garbage collection and an actual object system and it has compile time programming/type manipulation that puts C++ to shame.
It does still support pointer shenanigans and spectacularly unsafe casts, and even lets you tag code accordingly.
It has a sensible standard library and builtin things that C++ has clunky imports for.
It can link against C code.

It did right from the start (1999) everything the C++11/0x tries to fix now.

One noticable problem is that D 2.0 haven't got a port of Tango yet.
Other things is that it lacks ports for several major C libraries too, such as GMP and many GUI libraries.
EvanED wrote:be aware that when most people say "regular expression" they really mean "something that is almost, but not quite, entirely unlike a regular expression"
User avatar
MHD
 
Posts: 631
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

Re: Coding: Fleeting Thoughts

Postby EvanED » Thu Feb 09, 2012 7:12 pm UTC

[continuation of this discussion.]

darkone238 wrote:
Carnildo wrote:
EvanED wrote:(As a side note, every time I read the manpage for gettimeofday I feel like the next manpage I read is going to just be the lyrics of Never Gonna Give You Up. There are two parameters, but you are required to pass NULL for the second? It returns a value which is guaranteed to be 0? Whose idea of "good API design" is this?)

Sounds like you need a better man page. Mine explains why you should pass NULL (it's obsolete functionality that has never been supported on LInux), and that it returns -1 on failure; looking at the error codes it can return, the implementation on your system may not have any failure modes.


http://pubs.opengroup.org/onlinepubs/00 ... ofday.html

Maybe the Evan was looking at this :)

That's actually probably exactly what happened. For a few reasons I actually have a tendency to Google for man pages instead of just running 'man blah', and that is apparently the first hit if you do a Google search for gettimeofday().

That being said, I stand by my statement. Why would you put such a poorly-designed function in the standard? I guess I could see including it for backwards compatibility, but it should have been added and immediately deprecated, and an alternative provided which is not stupid. (clock_gettime() was added later, and at least my manpage says "is not widely supported.")
EvanED
 
Posts: 4141
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Coding: Fleeting Thoughts

Postby darkone238 » Thu Feb 09, 2012 8:47 pm UTC

EvanED wrote:[continuation of [notaurl=http://forums.xkcd.com/viewtopic.php?p=2880081#p2880081]this discussion[/notaurl].]

darkone238 wrote:
Carnildo wrote:
EvanED wrote:(As a side note, every time I read the manpage for gettimeofday I feel like the next manpage I read is going to just be the lyrics of Never Gonna Give You Up. There are two parameters, but you are required to pass NULL for the second? It returns a value which is guaranteed to be 0? Whose idea of "good API design" is this?)

Sounds like you need a better man page. Mine explains why you should pass NULL (it's obsolete functionality that has never been supported on LInux), and that it returns -1 on failure; looking at the error codes it can return, the implementation on your system may not have any failure modes.


http://pubs.opengroup.org/onlinepubs/009604599/functions/gettimeofday.html

Maybe the Evan was looking at this :)

That's actually probably exactly what happened. For a few reasons I actually have a tendency to Google for man pages instead of just running 'man blah', and that is apparently the first hit if you do [notaurl]http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=man+gettimeofday#pq=man+gettimeofday&hl=en&qe=IGdldHRpbWVvZmRheQ&qesig=YvrQphwe6SbSaLVrhNdgbg&pkc=AFgZ2tn7D4int2HK6y4e-WazF50g7EXbnLstZQLQIZXQFgUuCDJFW73s-2nk1-gUN-es4-ly8lMUoqxmbgVrAkYERrVaXzx4wQ&cp=0&gs_id=5&xhr=t&q=gettimeofday&pf=p&sclient=psy-ab&source=hp&pbx=1&oq=+gettimeofday&aq=0&aqi=g1g-c1g2&aql=&gs_sm=&gs_upl=&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=f2e3bb8212f508f6&biw=1678&bih=942]a Google search[/notaurl] for gettimeofday().

That being said, I stand by my statement. Why would you put such a poorly-designed function in the standard? I guess I could see including it for backwards compatibility, but it should have been added and immediately deprecated, and an alternative provided which is not stupid. (clock_gettime() was added later, and at least my manpage says "is not widely supported.")

http://linux.die.net/man/2/gettimeofday This seems to give a little more context into the function, but I think I agree with you that it should've just been deprecated. Why make decades of code have pointless parameters and depend on poorly defined return values (especially if there's some implementations that actually just return 0 no matter what. Why return anything?)?
User avatar
darkone238
 
Posts: 110
Joined: Thu Feb 09, 2012 6:37 am UTC

Re: Coding: Fleeting Thoughts

Postby Shivahn » Sat Feb 11, 2012 12:24 am UTC

Is there a newbie thread? Or, like, a newbie question thread? I have a question and I feel sort of weird posting in the fleeting thoughts thread.

Well, not so much weird as I think that I'm likely to have several others, and the "IT DOESN'T WORK" thread isn't appropriate either, as they're often style-related questions since I've learned all I have from the internet rather than formal instruction. If there isn't a thread like that, maybe I'll make one later, unless people think it's a bad idea for whatever reason...

Anyway, I'm on and off working on a simple game engine in C++. There is a source file for chunks that loads them and yada yada. And there's a source file for the creature class and subclasses, which handle all the interactions and such. And some other ones too. They all use (repeatedly) the pixel dimensions of a block, which is the fundamental unit of the world under this particular engine. I'm not sure what the appropriate style and way to handle this is. Do I have each of the header files include a header with constant definitions? Is there some other preferred way of doing this? I'd prefer not to have each header have a definition, since missing one during a change could cause numerous bugs. They'd all be easy to fix, probably, but I'd still rather be safe than sorry...

So, yes. What is the recommendation for something like this?
User avatar
Shivahn
 
Posts: 2193
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby EvanED » Sat Feb 11, 2012 12:33 am UTC

Shivahn wrote:Do I have each of the header files include a header with constant definitions? Is there some other preferred way of doing this? I'd prefer not to have each header have a definition, since missing one during a change could cause numerous bugs. They'd all be easy to fix, probably, but I'd still rather be safe than sorry...

You have good sense. You definitely don't want to repeat definitions like that. One header with the constant values that gets included everywhere would be perfectly reasonable if you want to set your dimensions globally like that.
EvanED
 
Posts: 4141
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Coding: Fleeting Thoughts

Postby Shivahn » Sat Feb 11, 2012 12:35 am UTC

Thanks! I'll do that. I'm glad to hear my ideas aren't totally senseless :P
User avatar
Shivahn
 
Posts: 2193
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Sat Feb 11, 2012 2:41 am UTC

EvanED wrote:
Shivahn wrote:Do I have each of the header files include a header with constant definitions? Is there some other preferred way of doing this? I'd prefer not to have each header have a definition, since missing one during a change could cause numerous bugs. They'd all be easy to fix, probably, but I'd still rather be safe than sorry...

You have good sense. You definitely don't want to repeat definitions like that. One header with the constant values that gets included everywhere would be perfectly reasonable if you want to set your dimensions globally like that.

It's a Good Idea to put include guard macros in a header that gets included by other headers, to prevent the header from being included multiple times. FWIW, I tend to put guard macros in all my headers, just to be on the safe side.
User avatar
PM 2Ring
 
Posts: 3297
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Mid north coast, NSW, Australia

Re: Coding: Fleeting Thoughts

Postby Shivahn » Sat Feb 11, 2012 2:58 am UTC

PM 2Ring wrote:
EvanED wrote:
Shivahn wrote:Do I have each of the header files include a header with constant definitions? Is there some other preferred way of doing this? I'd prefer not to have each header have a definition, since missing one during a change could cause numerous bugs. They'd all be easy to fix, probably, but I'd still rather be safe than sorry...

You have good sense. You definitely don't want to repeat definitions like that. One header with the constant values that gets included everywhere would be perfectly reasonable if you want to set your dimensions globally like that.

It's a Good Idea to put include guard macros in a header that gets included by other headers, to prevent the header from being included multiple times. FWIW, I tend to put guard macros in all my headers, just to be on the safe side.

Code::Blocks does that for me thankfully.

Which is good because otherwise I'd have SDL included like fifteen times. Which would be less than excellent.
User avatar
Shivahn
 
Posts: 2193
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sat Feb 11, 2012 3:15 pm UTC

Shivahn wrote:
PM 2Ring wrote:
EvanED wrote:
Shivahn wrote:Do I have each of the header files include a header with constant definitions? Is there some other preferred way of doing this? I'd prefer not to have each header have a definition, since missing one during a change could cause numerous bugs. They'd all be easy to fix, probably, but I'd still rather be safe than sorry...

You have good sense. You definitely don't want to repeat definitions like that. One header with the constant values that gets included everywhere would be perfectly reasonable if you want to set your dimensions globally like that.

It's a Good Idea to put include guard macros in a header that gets included by other headers, to prevent the header from being included multiple times. FWIW, I tend to put guard macros in all my headers, just to be on the safe side.

Code::Blocks does that for me thankfully.

Which is good because otherwise I'd have SDL included like fifteen times. Which would be less than excellent.


I'm fairly certain SDL has include guards in it's headers, so that won't be a danger.
I now occasionally update my rarely-updated blog.

I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.
User avatar
You, sir, name?
 
Posts: 6566
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City

Re: Coding: Fleeting Thoughts

Postby Shivahn » Sat Feb 11, 2012 10:38 pm UTC

Good point. Of course they do >.>

I have another question now. In Scheme, you can create function definitions within definitions, as in this sample:

Spoiler:
Code: Select all
(define (quadruple x)
  (define (double x) (* x 2))
  (double
   (double x)))


Is there a way to do this in C++? I wrote some code a while ago for the game engine that, now that I have better theory and understanding of modularity and organization and such, is terrible. It's a public function of the creature class that uses the entity's location, velocity, width, and environmental location and checks for collisions and resolves them. I want to make a helper function that takes those and returns the adjustment that needs to be done to avoid a collision with the environment, and I'd like to make one separately for left, right, up and down. I think doing it that way would be easier than having one big function that has a mess of if trees and keeps track of everything and does it all at once. But it'd be only used for that function: finding and resolving environmental collisions. So if at all possible, I don't want to declare it in the class definition.

Is there a way to do that? And if so, is that just a terrible way to go about things, or all right?
User avatar
Shivahn
 
Posts: 2193
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sat Feb 11, 2012 10:51 pm UTC

Short answer: No.

Long answer: Yes, but only in C++11.
I now occasionally update my rarely-updated blog.

I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.
User avatar
You, sir, name?
 
Posts: 6566
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City

Re: Coding: Fleeting Thoughts

Postby Shivahn » Sat Feb 11, 2012 11:02 pm UTC

Ok, I'll just think of some other way to do it for now. It's not a huge amount of code anyway, it just offends my aesthetic sensibilities.
User avatar
Shivahn
 
Posts: 2193
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby EvanED » Sat Feb 11, 2012 11:23 pm UTC

You can still break it off. If you are implementing your functions inside the class definition, i.e.
Code: Select all
class MyClass {
  public:
    void doSomething() {
        blah();
        blah();
   }
};

then you can at least make the helper functions private.

If you are implementing your functions in a separate .cpp file, then you can make that functions just available in that file, and people who are using your class won't even know they exists. You can do this either by putting those functions inside the unnamed namespace:
Code: Select all
namespace
{
    void helperFunction1()
    {
        ...
    }
}

or by marking them static:
Code: Select all
static void helperFunction1()
{
    ....
}

(This is a different meaning for static from static class members or function variables.) Both of these will make it so that other compilation units can't link against those functions.
EvanED
 
Posts: 4141
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Coding: Fleeting Thoughts

Postby Xanthir » Sun Feb 12, 2012 1:24 am UTC

Fleeting Thoughts seems most appropriate for this.

I just got a new tattoo today - a unix timestamp of my wedding date. Here's the pattern, and the finished result.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4323
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Coding: Fleeting Thoughts

Postby Shivahn » Sun Feb 12, 2012 2:10 am UTC

Thanks, Evan. The static method looks like what I was going for, just in a slightly different place.

That's super awesome Xanthir! Personal in several ways, I like it :P
User avatar
Shivahn
 
Posts: 2193
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby Link » Mon Feb 13, 2012 5:45 pm UTC

What I thought would be a 30-minute coding job turned out to be a pretty large can of worms. Well, the naive approach was indeed a 30-minute coding job. Unfortunately, the output is the digital equivalent of the Thousand Young of Shub-Niggurath*. The non-naive approach is of the sort where a Google search on the subject turns up a frightening amount of pages with the text "buy this article".

*Technically speaking, the output is not incorrect as such, but it's one of the ugliest, most inefficient and sanity-shatteringly voluminous ways to represent the data in question.
User avatar
Link
418 I'm a teapot
 
Posts: 984
Joined: Sat Mar 07, 2009 11:33 am UTC
Location: ᘝᓄᘈᖉᐣ

Re: Coding: Fleeting Thoughts

Postby Xeio » Mon Feb 13, 2012 7:14 pm UTC

Having a private property, and then a private field that stores the value of that property: Good.

Setting the value of the property to the value of the field (which then resets the value of the field to... itself...): Not so good.

I guess at least it isn't broken. Though I'm sort of scared to try and dig deep enough to figure out if there's a reason they're trying to work around the side effects caused by the Set on the property...

Luckily this doesn't seem related to my current bug...
User avatar
Xeio
Friends, Faidites, Countrymen
 
Posts: 4805
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\

Re: Coding: Fleeting Thoughts

Postby Jplus » Mon Feb 13, 2012 7:21 pm UTC

MHD wrote:
Jplus wrote:[not enthusiastic about D]

It has builtin garbage collection
Even if you can switch it off and use unified deterministic resource management instead (and I suspect you can't), I don't consider that an advantage over C++. Although in that case it wouldn't be a drawback either.
MHD wrote:and an actual object system
What do you mean by that? What's not real about C++' object system?
MHD wrote:and it has compile time programming/type manipulation that puts C++ to shame.
I've heard a similar claim before, but I couldn't find any clear hints at the Digital Mars and D programming language websites on how D would be better at this than C++. Care to give an example?

MHD wrote:It does still support pointer shenanigans and spectacularly unsafe casts, and even lets you tag code accordingly.
Does the tagging offer any advantage, apart from documentation (which you could also do with plain comments)? E.g. does it allow the compiler to do anything special?
MHD wrote:It has a sensible standard library
Not a difference.
MHD wrote:and builtin things that C++ has clunky imports for.
Well that's nice, but I suspect many more libraries are available for C++ overall. It's kind of sweet to provide a big standard library, but it's not of much use if you still have less options overall.
MHD wrote:It can link against C code.
Not a difference.

MHD wrote:It did right from the start (1999) everything the C++11/0x tries to fix now.
Oh really? Like what? I can find that D has some standard libraries which are now introduced as standard libraries in C++, such as threading and regex, but that again only obscures the fact that more libraries are available for C++ overall. The website doesn't seem to mention any core features that C++ didn't have until now (e.g. lambdas). Even if there are such things they bear little practical relevance because, well, C++ now has them too.
(Oh wait, I can find one thing. C++11 got class member initializers as a new feature, while apparently D already had them.)

MHD wrote:One noticable problem is that D 2.0 haven't got a port of Tango yet.
Other things is that it lacks ports for several major C libraries too, such as GMP and many GUI libraries.
Let's just face that less libraries are available for D.

I can find one thing that D has and which C++ lacks completely, and that's the immutable modifier. A rather meager advantage IMO, given how C++ and D compare otherwise. Rust does a better attempt than D to be "better than C++" in that regard. On the other hand it lacks more of the good things as well (such as Turing-complete generics).
Feel free to call me Julian. J+ is just an abbreviation.
Image coding and xkcd combined
User avatar
Jplus
 
Posts: 1558
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: classified

Re: Coding: Fleeting Thoughts

Postby Xeio » Wed Feb 15, 2012 10:45 pm UTC

See, now I would think that "bool ValidateX(X)" would return true if X was valid.

Of course, I must be crazy to follow convention like that.
User avatar
Xeio
Friends, Faidites, Countrymen
 
Posts: 4805
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Thu Feb 16, 2012 4:18 am UTC

Xeio wrote:See, now I would think that "bool ValidateX(X)" would return true if X was valid.

Of course, I must be crazy to follow convention like that.

Sometimes in C non-zero means error and zero means success. Assuming this is C++ (or something else with a "bool" primitive), someone may have decided to carry over that convention just for consistency.

Still kind of stupid, though.
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.
User avatar
TheChewanater
 
Posts: 1286
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Thu Feb 16, 2012 4:33 am UTC

TheChewanater wrote:
Xeio wrote:See, now I would think that "bool ValidateX(X)" would return true if X was valid.

Of course, I must be crazy to follow convention like that.

Sometimes in C non-zero means error and zero means success. Assuming this is C++ (or something else with a "bool" primitive), someone may have decided to carry over that convention just for consistency.

Still kind of stupid, though.

Yeah. The integer error code convention is zero for no error, with various non-zero codes for actual errors. If it's a bool then true ought to mean good and false should mean bad.

And then there's the convention where valid data is returned as a non-negative integer, and negative integer(s) signify an error, or no data, eg the EOF code returned by getchar() is (generally) -1.
User avatar
PM 2Ring
 
Posts: 3297
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Mid north coast, NSW, Australia

Re: Coding: Fleeting Thoughts

Postby Xeio » Thu Feb 16, 2012 2:22 pm UTC

Don't worry, neither of those apply in C#, or even in our codebase.

Doesn't matter though, they're passing in "T as IEnumerable<T>" (Hint: T is a non-enumerable-castable class, let alone an enumerable of itself) into the parameter, and the method returns a "valid" if the parameter is null. <_<

(I didn't even notice that casting bit when I wrote my previous post, so, woo...)
User avatar
Xeio
Friends, Faidites, Countrymen
 
Posts: 4805
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\

Re: Coding: Fleeting Thoughts

Postby jareds » Sun Feb 19, 2012 3:45 am UTC

I recently noticed that, in Visual Studio 2010, C++ Intellisense (underlining errors, etc. in the editor) is almost surely using the EDG front-end rather than the front-end of the actual MSVC compiler (various cases rejected by EDG and Intellisense but accepted by the MSVC compiler, and vice versa). In fact this can be verified here http://blogs.msdn.com/b/vcblog/archive/2009/05/27/rebuilding-intellisense.aspx.

Nothing against EDG, but I do wonder if they are eventually going to be the only proprietary C++ front-end.
jareds
 
Posts: 414
Joined: Wed Jan 03, 2007 3:56 pm UTC

Re: Coding: Fleeting Thoughts

Postby EvanED » Sun Feb 19, 2012 8:46 am UTC

The EDG folks are crazy good, as are their front ends. (Though looking into it, it seems that at least Comeau is actually lagging well behind both GCC and MSVC on C++11 support.)

But as much as I'd like to see MSVC take up the EDG front end, I sort of doubt they will. That would break a lot of existing code, as the current MS compiler is way off spec in some respects. In particular, it doesn't implement two-phase name lookup for templates; practically speaking this leads to just being way too permissive, but it can lead to silent changes of behavior.

That said, I don't have much experience with using EDG compilers (mostly just an occasional flirt with Intel CC and the Comeau online try-it-out thing), but I actually really like MSVC's error messages. I tend to find them far more readable than GCC's. So hopefully either EDG is up-to-par (which wouldn't surprise me) or they bring it there before taking it up.
EvanED
 
Posts: 4141
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Coding: Fleeting Thoughts

Postby jareds » Sun Feb 19, 2012 10:28 am UTC

EvanED wrote:But as much as I'd like to see MSVC take up the EDG front end, I sort of doubt they will. That would break a lot of existing code, as the current MS compiler is way off spec in some respects. In particular, it doesn't implement two-phase name lookup for templates; practically speaking this leads to just being way too permissive, but it can lead to silent changes of behavior.

Just to be clear, I meant that Intellisense resembles EDG --microsoft --microsoft_bugs, not default EDG; and presumably default EDG would be named something like --strict under MSVC if they switched front-ends. That said, obviously their compatibility is imperfect or we wouldn't be having this conversation--and it could easily be enough to matter in practice. Overall, I do think the idea of MS replacing their front-end is very speculative, but I was quite surprised to notice that Intellisense was not using the same front-end as the compiler.

That said, I don't have much experience with using EDG compilers (mostly just an occasional flirt with Intel CC and the Comeau online try-it-out thing), but I actually really like MSVC's error messages. I tend to find them far more readable than GCC's. So hopefully either EDG is up-to-par (which wouldn't surprise me) or they bring it there before taking it up.

And I don't have enough experience with MSVC to compare...but I do think EDG's are better than GCC's.
jareds
 
Posts: 414
Joined: Wed Jan 03, 2007 3:56 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Sun Feb 19, 2012 10:56 am UTC

I continuously get this kind of code from my coworkers who try to write PHP:

Code: Select all


function get_user_email($id){
    
$q query("SELECT `email` from `users` where `id`='".mysql_real_escape_string($id)."'");
    if(
mysql_num_rows($q) == 0){
        return 
RESULT_ERROR_NOT_FOUND
    
}else{
        return array(
mysql_result($q0'email'), RESULT_OK);
    }
}

function 
display_user_email($id){
    
$email get_user_email($id);
    if(
is_okay($email)) echo "<div>" $email[0] . "</div>"
}
 


Whoever invented exceptions is now thrashing uncontrollably in his/her grave.
In Minecraft, I use the username Rirez.
User avatar
Steax
SecondTalon's Goon Squad
 
Posts: 3037
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby EvanED » Sun Feb 19, 2012 12:50 pm UTC

jareds wrote:
EvanED wrote:But as much as I'd like to see MSVC take up the EDG front end, I sort of doubt they will. That would break a lot of existing code, as the current MS compiler is way off spec in some respects. In particular, it doesn't implement two-phase name lookup for templates; practically speaking this leads to just being way too permissive, but it can lead to silent changes of behavior.

Just to be clear, I meant that Intellisense resembles EDG --microsoft --microsoft_bugs, not default EDG; and presumably default EDG would be named something like --strict under MSVC if they switched front-ends.

Oh, EDG already being able to somewhat emulate MSVC didn't occur to me. Do you know how close it gets? E.g. does it at least mostly get their template lookup right? Or is it just some stuff more on the parser side?

Actually what would be really cool is if they implemented both, then had a mode that was like --strict-assist or something. I bet it could even automatically add typename where needed, warn in locations where changing to two-phase lookup changes name bindings, and maybe some other things.

I was quite surprised to notice that Intellisense was not using the same front-end as the compiler.

Same here. I heard about it a while back but don't use VS enough (unfortunately) to really have an opportunity to notice much. I think there have been a few times when it's underlined stuff wrong, but I just chalked that up to not getting preprocessor flags quite right and stuff.
EvanED
 
Posts: 4141
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

PreviousNext

Return to Coding

Who is online

Users browsing this forum: No registered users and 3 guests