Coding: Fleeting Thoughts

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

Moderators: phlip, Moderators General, Prelates

User avatar
Shivahn
Posts: 2200
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby Shivahn » Wed Jun 13, 2012 4:12 am UTC

Cool, thanks. I'll take a stab at that later tonight.

Reimplementing standard functions is a fine class of problems, I'd forgotten all about trying that! Thanks again.

Ben-oni
Posts: 278
Joined: Mon Sep 26, 2011 4:56 am UTC

Re: Coding: Fleeting Thoughts

Postby Ben-oni » Wed Jun 13, 2012 4:29 am UTC

@Steax: You know better, right? While CSS allows "px" units, they're really not recommended. It's much better to use "pt" units, which is a physical unit of length.

But I believe the real question in there was "Which software layer determines how large things are?" Obviously, the bottom one. Every layer above that has a coordinate transform progressively applied to it. As far as OS X goes, Quartz has been doing it this way from the beginning. While a program might pretend that '1' unit of length is a pixel, it's not. The end result is that programs that refuse to recognize fractional pixel lengths will just look... pixelated. So, vectorized graphics will look good, bitmaps... less good.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Wed Jun 13, 2012 4:50 am UTC

Well, yes, but pt was horribly unreliable in the past due to browser differences (remember the old solution about ems and setting everything to 76% baseline?) so it never really got traction, and pixels because de facto in CSS.

Thing is, nobody seems to have picked a base unit to work off - I suppose that points would work well, but I'm not sure if there's even any standard for it; does anything even obey the 72pt = 1 inch rule from typography? I know this iPhone in front of me is 3"x2", which should equate to 216pt x 144pt. It's 960px x 640px, which means it has a ratio on pixels to points of, let's see... 4.444... pixels per point. On the other end, this site suggests that in web typography, it's 13 pixels to a point.

We all know the iPhone simply decided to scale up by four times (surface area) upon the 4th generation; the decision to keep it at 480x320 "meta-pixels" in software was just to ease the transition and make sure CSS media queries didn't break. The choice to even use 480x320 was historical, not mathematical.

The only way to reliably get it to work on the web everywhere is to build at high resolution, then shrink it before displaying, and hope the layer managing this process can pick up our original resolution image and work off that.

Now my head hurts.

(I know someone really smart must know the truth here, but I just can't find it. Give us some non-ephemeral unit, please. I may also be blabbering total nonsense.)
Last edited by Steax on Wed Jun 13, 2012 5:31 am UTC, edited 1 time in total.
In Minecraft, I use the username Rirez.

User avatar
joshz
Posts: 1466
Joined: Tue Nov 11, 2008 2:51 am UTC
Location: Pittsburgh, PA

Re: Coding: Fleeting Thoughts

Postby joshz » Wed Jun 13, 2012 5:19 am UTC

I can now confirm that Xanthir is a pretty cool dude.
You, sir, name? wrote:If you have over 26 levels of nesting, you've got bigger problems ... than variable naming.
suffer-cait wrote:it might also be interesting to note here that i don't like 5 fingers. they feel too bulky.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Wed Jun 13, 2012 6:06 am UTC

I'm secretly hoping he has a solution for this pixel problem. =(

(This finally got to the edge with the new macbook pro, which will likely lead the way for future high-resolution desktop displays. Smartphones aren't used to browse too much, and they have apps. Tablets still have apps, and we look at them at varied distances, making a bit of blurriness okay. But big screens? It'll be a mess.)
In Minecraft, I use the username Rirez.

Ben-oni
Posts: 278
Joined: Mon Sep 26, 2011 4:56 am UTC

Re: Coding: Fleeting Thoughts

Postby Ben-oni » Wed Jun 13, 2012 6:13 am UTC

Steax wrote:Well, yes, but
Spoiler:
pt was horribly unreliable in the past due to browser differences (remember the old solution about ems and setting everything to 76% baseline?) so it never really got traction, and pixels because de facto in CSS.

Thing is, nobody seems to have picked a base unit to work off - I suppose that points would work well, but I'm not sure if there's even any standard for it; does anything even obey the 72pt = 1 inch rule from typography? I know this iPhone in front of me is 3"x2", which should equate to 216pt x 144pt. It's 960px x 640px, which means it has a ratio on pixels to points of, let's see... 4.444... pixels per point. On the other end, this site suggests that in web typography, it's 13 pixels to a point.

We all know the iPhone simply decided to scale up by four times (surface area) upon the 4th generation; the decision to keep it at 480x320 "meta-pixels" in software was just to ease the transition and make sure CSS media queries didn't break. The choice to even use 480x320 was historical, not mathematical.

The only way to reliably get it to work on the web everywhere is to build at high resolution, then shrink it before displaying, and hope the layer managing this process can pick up our original resolution image and work off that.

Now my head hurts.

(I know someone really smart must know the truth here, but I just can't find it. Give us some non-ephemeral unit, please. I may also be blabbering total nonsense.)

I did not, in fact, know any of that. Well, except for the fact that I almost always use "px" units :p. Then again, I only ever do as little CSS as necessary, and assume someone more knowledgable in the area (maybe a graphic artist? There must be someone who specializes in creating wonderful layout and styles) will do it right later on (of course, if the web is any indication, this rarely happens). I excuse my deficiency in this area by claiming that markup and styling have almost nothing to do with programming (which is bogus inasmuch as UI design is part of programming).

Anyone know where to find a set of exercises for practicing CSS skills?

User avatar
Xanthir
My HERO!!!
Posts: 5410
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Wed Jun 13, 2012 7:04 pm UTC

Ben-oni wrote:@Steax: You know better, right? While CSS allows "px" units, they're really not recommended. It's much better to use "pt" units, which is a physical unit of length.

Sorry, this is wrong. For web-compatibility reasons*, the ratio between "px" and "pt" (and all the other "physical" units) is fixed. 1pt === 4/3px forever, 1in = 96px forever, etc. Browsers can decide exactly how large these should be (for example, either sizing px to be an integer number of device pixels, or sizing in to be a real inch), but once they've done so for one of them, the rest are automatically defined relative to it.

ETA:
* The reasons are that most people only test their stuff in the computer they have, so they never think of the fact that people have different resolutions, which would produce differing size ratios between px and the physical length units. Thus, they make pages that mix the two and break if the ratio changes.
Last edited by Xanthir on Wed Jun 13, 2012 7:59 pm UTC, edited 1 time in total.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

Ben-oni
Posts: 278
Joined: Mon Sep 26, 2011 4:56 am UTC

Re: Coding: Fleeting Thoughts

Postby Ben-oni » Wed Jun 13, 2012 7:18 pm UTC

Xanthir wrote:
Ben-oni wrote:@Steax: You know better, right? While CSS allows "px" units, they're really not recommended. It's much better to use "pt" units, which is a physical unit of length.

Sorry, this is wrong. For web-compatibility reasons, the ratio between "px" and "pt" (and all the other "physical" units) is fixed. 1pt === 4/3px forever, 1in = 96px forever, etc. Browsers can decide exactly how large these should be (for example, either sizing px to be an integer number of device pixels, or sizing in to be a real inch), but once they've done so for one of them, the rest are automatically defined relative to it.

Further evidence of how antiquated my CSS knowledge really is.

User avatar
Xanthir
My HERO!!!
Posts: 5410
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Wed Jun 13, 2012 8:06 pm UTC

Steax wrote:I wonder how the web (in particular, CSS) will deal with new high-resolution monitors*. How can we rely on pixels when these devices pretend to be a certain size, while upscaling graphics that lack the scalability? We now have "true" physical pixels and "software" pixels. Who decides what goes where? How does this work? WHY AM I BEING SO CONFUSED?

*) Yes, I know they've been around for a while - it's just that Apple's bringing them to their audience is giving it a nice hefty boost to mainstream.

CSS itself doesn't give a crap about high-def - it's effectively a vector format. The CSS px unit is not connected to device pixels, except that in practice browsers ensure that an integer number of device pixels map to a CSS px. Images are locked to a resolution of one image pixel = one CSS px.

For when you do want to send a high-res image, there are a few features emerging right now. On the HTML side there's the <img srcset> attribute, which lets you tell the UA about several images at different resolutions, and let it choose which one it wants to download, based on its own factors like screen res, bandwidth, etc. Once I get the time to edit CSS4 Images again, I'll add the nearly identical image-set() function to it, which lets you do the same thing in CSS.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Wed Jun 13, 2012 8:49 pm UTC

I did not know that C# defined the bitwise operators for booleans as well.

I don't know how I feel about this. I guess it's not bad, just weird, particularly when I noticed for the first time in our codebase someone used | instead of || with booleans.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Wed Jun 13, 2012 8:59 pm UTC

| is logical or on booleans (not "bitwise"), but does not short-circuit. I guess you could just say that booleans are 1 bit values, in which case logical or is equivalent to bitwise or!
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: Coding: Fleeting Thoughts

Postby Sc4Freak » Wed Jun 13, 2012 9:43 pm UTC

Also, booleans aren't convertible to integers in C#, so | must necessarily mean logical OR because bitwise isn't meaningful.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Wed Jun 13, 2012 11:23 pm UTC

So I have a C++ vector<string>. I need to convert it into a char const ** in the style of argv, that is a list of string pointers terminated with a null.

What's the best/safest way to do this? What I have now is pretty ugly. :-) (My code includes the comment "free() the inner arrays and delete[] the outer one" which you just know is a wonderful sign.) In a departure from the norm, I have access to the portion of C++11 common to GCC 4.6+ and MSVC 2010+.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Thu Jun 14, 2012 12:56 am UTC

Code: Select all

class cargs {
        int _argc;
        char** _argv;
public:

        int argc() const { return _argc; }
        char** argv() const { return _argv; }

        ~cargs() {
                for(int i = 0; i < _argc; i++) {
                        delete[] _argv[i];
                }
                delete[] _argv;
        }
        cargs(const cargs&) = delete;
        cargs& operator=(const cargs&) = delete;

        cargs(const std::vector<std::string>& in) : _argc(in.size()), _argv(new char*[in.size()]) {
                for(int i = 0; i < _argc; i++) {
                        const std::string& str = in[i];
                        int len = str.length();
                        char * nstr = _argv[i] = new char[len + 1];
                        std::copy(str.begin(), str.end(), nstr);
                        nstr[len] = '\0';
                }
        }

};



would be my ansatz for a solution without knowing the constraints. You can of course to weird stuff like wrapping it all in one contiguous memory area, but I don't see an immediate benefit from that (besides saving mallocs).

Or are you trying to create an array of the internal pointers of std::string or something? Or using strdup?
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Thu Jun 14, 2012 2:16 am UTC

Ben-oni wrote:
Anyone know where to find a set of exercises for practicing CSS skills?


CSS has really been on the move lately, it's kind of... difficult. My old sources probably wouldn't do well nowadays.

Xanthir wrote:
Steax wrote:I wonder how the web (in particular, CSS) will deal with new high-resolution monitors*. How can we rely on pixels when these devices pretend to be a certain size, while upscaling graphics that lack the scalability? We now have "true" physical pixels and "software" pixels. Who decides what goes where? How does this work? WHY AM I BEING SO CONFUSED?

*) Yes, I know they've been around for a while - it's just that Apple's bringing them to their audience is giving it a nice hefty boost to mainstream.

CSS itself doesn't give a crap about high-def - it's effectively a vector format. The CSS px unit is not connected to device pixels, except that in practice browsers ensure that an integer number of device pixels map to a CSS px. Images are locked to a resolution of one image pixel = one CSS px.

For when you do want to send a high-res image, there are a few features emerging right now. On the HTML side there's the <img srcset> attribute, which lets you tell the UA about several images at different resolutions, and let it choose which one it wants to download, based on its own factors like screen res, bandwidth, etc. Once I get the time to edit CSS4 Images again, I'll add the nearly identical image-set() function to it, which lets you do the same thing in CSS.


Yeah, I'm aware that CSS just works with the provided pixels as defined by the browser/whatever software layer is there. My issue is how there exists an unknown number of actual device pixels (only detectable through the -webkit-device-pixel-ration media query), and that's all we have to work with in order to serve actual high-quality images. It just feels odd that, no, you don't need a 100x100px image for a 100x100px element. You need a 200x200px image for that element to look best. It's just... strange and disconcerting.

Glad to see solutions are being built, though. I haven't heard of srcset, though I guess that's just because it's so new. I've been forced to always serve high resolution images and scale them down from there (it's a bandwidth sucker but there aren't really many options). Also using background-size and CSS sprites have been working perfectly well for me as well so far.
In Minecraft, I use the username Rirez.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Thu Jun 14, 2012 2:57 am UTC

EvanED wrote:So I have a C++ vector<string>. I need to convert it into a char const ** in the style of argv, that is a list of string pointers terminated with a null.

What's the best/safest way to do this? What I have now is pretty ugly. :-) (My code includes the comment "free() the inner arrays and delete[] the outer one" which you just know is a wonderful sign.) In a departure from the norm, I have access to the portion of C++11 common to GCC 4.6+ and MSVC 2010+.

How do you want to manage the lifetime of said buffers? Can you keep a (C++ class) whose job it is to RAII the lifetime?

If so:

Code: Select all

struct c_args
{
  std::vector<std::string> original_buffer;
  std::vector<const char*> c_buffer;
  void make_c_buffer()
  {
    std::foreach( original_buffer.begin(), original_buffer.end, [&](std::string const& ) { c_buffer.push_back(s.c_str()); }
    c_buffer.push_back(nullptr);
  }
  c_args( std::vector<std::string> orig ): original_buffer(orig) { make_c_buffer(); }
  c_args( c_args const& other ): original_buffer( other.original_buffer) { make_c_buffer(); }
  c_args( c_args&& other ): original_buffer(std::move(other.original_buffer) { make_c_buffer(); other.c_buffer.clear(); }
  char const*const* get_c_buffer() const { return &c_buffer.front(); }
  size_t get_c_length() const { return c_buffer.size(); }
};

Now, this generates a char const*const* instead of the char const** you asked for, but removing that extra const is pretty easy.

The lifetime of the get_c_buffer() return is the lifetime of the c_args struct you got it from c_args can be copied around, but each instance of c_args you create has a different c_buffer -- if you don't like that feature, have it use shared_ptr for both of the std::vectors, and remove the non-std::vector constructor, and the lifetime of the c_buffer will be the lifetime of the last c_args that refers to it.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Shivahn
Posts: 2200
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby Shivahn » Thu Jun 14, 2012 4:17 am UTC

I have a quick Haskell implementation recursion question.

I see a lot of Haskell implementations of functions like length that are of the variety

Code: Select all

length' :: [a] -> Int
length' [] = 0
length' (_:xs) = 1 + length' xs


So... in Scheme, my understanding is that this would be bad, as it leaves the pending +1 and thus takes up increasing amounts of space, whereas making a function that takes an accumulator and a list would be tail optimized.

Is this the case in Haskell, or does Currying mean that there's no difference? Since really what's going on, as I understand it, is that a function is created that adds 1 to length' xs, and that function then evaluates length' xs, which is a function that adds 1 to the length' (tail of xs), so now what we have is a function that adds 2 to length' (tail of xs), and so on.

Sorry, I realize that's not super clear but I don't quite know how to phrase it otherwise. Am I correct in assuming that Currying saves us from that being suboptimal? Or am I misunderstanding it (or, misunderstanding what's going on under the hood?)

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Thu Jun 14, 2012 4:30 am UTC

Yakk wrote:
EvanED wrote:So I have a C++ vector<string>. I need to convert it into a char const ** in the style of argv, that is a list of string pointers terminated with a null.

What's the best/safest way to do this? What I have now is pretty ugly. :-) (My code includes the comment "free() the inner arrays and delete[] the outer one" which you just know is a wonderful sign.) In a departure from the norm, I have access to the portion of C++11 common to GCC 4.6+ and MSVC 2010+.

How do you want to manage the lifetime of said buffers? Can you keep a (C++ class) whose job it is to RAII the lifetime?

I can do pretty much anything. What I was sort of hoping for was someone to say "unique_ptr<T> is guaranteed to be layout-compatible with T* and so you can use a vector<unique_ptr<char const*>>" or something like that. :-)

Since it's just a one-off thing, right now I just have this (actually incorrect because I remembered I need to null-terminate it just before leaving for the day; that leads to simplifications because I don't need to pass the size to the free function which means I don't need the lambda)

Code: Select all

/// Converts the given vector into an array of char*s, so that they can be
/// passed to processCreate or whatnot. free() the inner arrays and delete[]
/// the outer one.
char const **
toCharPointerArray(vector<string> const & vec)
{
    char const ** array = new char const *[vec.size() + 1];
    for (size_t i=0; i<vec.size(); ++i) {
        array[i] = strdup(vec[i].c_str());
    }
    array[vec.size()] = nullptr;
    return array;
}

/// Frees an array allocated by toCharPointerArray
///
void
freeCharPointerArray(char const ** array, size_t outer_dimension)
{
    for (size_t i=0; i<outer_dimension; ++i) {
        free(const_cast<char*>(array[i]));
    }
    delete[] array;
}
...
shared_ptr<char const *> argv(toCharPointerArray(argv_vector),
                              [&argv_vector](char const ** array) {
                                  freeCharPointerArray(array, argv_vector.size());
                              });

Pixyn25
Posts: 10
Joined: Thu Feb 02, 2012 6:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Pixyn25 » Thu Jun 14, 2012 5:30 am UTC

Shivahn wrote:

Code: Select all

length' :: [a] -> Int
length' [] = 0
length' (_:xs) = 1 + length' xs



The above definition is not tail-recursive, and will probably cause an O(n) usage of stack/memory space.
Instead, to write in a tail-recursive way, try this:

Code: Select all

length'' :: [a] -> Int
length'' x = length_iter x 0
        where length_iter [] n = n
              length_iter (_:xs) n = length_iter xs (n+1)


Currying is when you have a function that takes multiple arguments, you can 'partially-apply' it to create a function that takes the rest of the arguments.

As an example, a curried "fold" function:
The fold function takes three arguments: a function to fold the list with, an initial 'seed' value, and a list to fold.
A non-curried version would always take exactly 3 arguments, no more, no less.
The curried version can take just one or two arguments, and return a function that is able to take the rest of the arguments.

Code: Select all

sum xs = foldr (+) 0 xs
-- could also be written like this
another_sum = foldr (+) 0 -- notice that only 2 args are passed in

-- as another example
add_2 = (2+)
-- same as: add_2 x = 2+x or: add_2 = \x -> 2+x


I don't think currying and tail-recursion have any relation with each other, but correct me if I'm wrong.

Code: Select all

town.addChangeListener(new ChangeListener(){
   public void stateChanged(ChangeEvent e){
      if(e instanceof NewPersonInTown) throw new WelcomeParty();
   }
}

Take off your shipping goggles and put on the friendshipping goggles instead.

User avatar
chridd
Has a vermicelli title
Posts: 843
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: Coding: Fleeting Thoughts

Postby chridd » Thu Jun 14, 2012 6:10 am UTC

Shivahn wrote:I have a quick Haskell implementation recursion question.

I see a lot of Haskell implementations of functions like length that are of the variety

Code: Select all

length' :: [a] -> Int
length' [] = 0
length' (_:xs) = 1 + length' xs


So... in Scheme, my understanding is that this would be bad, as it leaves the pending +1 and thus takes up increasing amounts of space, whereas making a function that takes an accumulator and a list would be tail optimized.

Is this the case in Haskell, or does Currying mean that there's no difference? Since really what's going on, as I understand it, is that a function is created that adds 1 to length' xs, and that function then evaluates length' xs, which is a function that adds 1 to the length' (tail of xs), so now what we have is a function that adds 2 to length' (tail of xs), and so on.

Sorry, I realize that's not super clear but I don't quite know how to phrase it otherwise. Am I correct in assuming that Currying saves us from that being suboptimal? Or am I misunderstanding it (or, misunderstanding what's going on under the hood?)
Are you perhaps thinking of laziness? It won't help for length (since integers can't be partially evaluated (don't know if that's the proper term), at least as far as I know), but if you have something that returns a list, for instance

Code: Select all

map _ [] = []
map f (x:xs) = f x : map f xs
then it doesn't evaluate the recursive call to map until some other code tries to look at the tail of the list, and depending on what happens with the result, it might not process the whole list at all (important for infinite lists). (In fact, I think if you write map in a tail-recursive way it will look at the whole list, though not the elements in the list.)
(And, as Pixyn25 mentioned, this doesn't have much to do with currying.)
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · she · Forum game scores
mittfh wrote:I wish this post was very quotable...

elminster
Posts: 1560
Joined: Mon Feb 26, 2007 1:56 pm UTC
Location: London, UK, Dimensions 1 to 42.
Contact:

Re: Coding: Fleeting Thoughts

Postby elminster » Thu Jun 14, 2012 1:19 pm UTC

Thoughts on Visual Studio 2012: What in gods name have they done with the styling!?!
I know their motives and stuff, but the implementation is just kinda bad. Photoshops interface looks clean without looking so retro.
I'm confused as to why you'd need a link to "New project" on your menu bar as default but leave out more commonly used things (Given their motives of creating a minimal and simple interface, partly by removing clutter) . It's not like "New project" is an action you'd use very often (Relative to save, open file, run, and many other things).
Image

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Thu Jun 14, 2012 2:21 pm UTC

elminster wrote:Thoughts on Visual Studio 2012: What in gods name have they done with the styling!?!
I know their motives and stuff, but the implementation is just kinda bad. Photoshops interface looks clean without looking so retro.

I haven't used it, but from the couple screenshots I'm not quite sure what you mean. AT LEAST ASIDE FROM THE MENU NAMES.

I'm confused as to why you'd need a link to "New project" on your menu bar as default but leave out more commonly used things (Given their motives of creating a minimal and simple interface, partly by removing clutter) . It's not like "New project" is an action you'd use very often (Relative to save, open file, run, and many other things).

Hmm, I do sorta see your point. Though if I'd hazard a guess, I'd almost say those other things you mention at least are used too commonly to be worth much space on the menu bar considering that I suspect most people know and use the keyboard shortcuts for them. (Though I do tend to use the save-all from the toolbar.)

User avatar
Shivahn
Posts: 2200
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby Shivahn » Thu Jun 14, 2012 4:30 pm UTC

Ohh, yeah, thanks you guys.

I guess what I'm learning from simplified things so that it doesn't have to do more complex code, which ironically confused me (because I figured they'd be performing all the simple optimizations).

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Thu Jun 14, 2012 5:04 pm UTC

EvanED wrote:
elminster wrote:Thoughts on Visual Studio 2012: What in gods name have they done with the styling!?!
I know their motives and stuff, but the implementation is just kinda bad. Photoshops interface looks clean without looking so retro.

I haven't used it, but from the couple screenshots I'm not quite sure what you mean. AT LEAST ASIDE FROM THE MENU NAMES.


It's quite telling how I can't even seem to find any screenshots on their website at all. Or... I may be missing them.
In Minecraft, I use the username Rirez.

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: Coding: Fleeting Thoughts

Postby Sc4Freak » Thu Jun 14, 2012 5:24 pm UTC

I think as a software company, Microsoft is past the point of posting screenshots of their applications on the frontpage of their website. I don't think Office or Windows have screenshots on their frontpages either. :P

I've been following VS2012 reasonably closely and it's astounding just how much attention there is over something as trivial as casing of the main menu. It's ALLCAPS now instead of Title Case now... who cares? I'd rather that they focused on getting the rest of C++11 implemented! Bikeshedding in action?

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Thu Jun 14, 2012 6:05 pm UTC

Sc4Freak wrote:I've been following VS2012 reasonably closely and it's astounding just how much attention there is over something as trivial as casing of the main menu. It's ALLCAPS now instead of Title Case now... who cares?

'Cause it's fucking ugly? :-)

I'd rather that they focused on getting the rest of C++11 implemented! Bikeshedding in action?

I've expressed my desire that they work on that too, in the past.

But it's more than that. Hoping that they'll change the menus is more realistic than hoping they'll implement more C++11; the actual work would probably take someone who knows what they're doing 5 minutes plus whatever testing they have to do. Implementing, say, variadic templates is asking way way more of them. So it's also a case of "focus on the battles you may be able to win."

Ben-oni
Posts: 278
Joined: Mon Sep 26, 2011 4:56 am UTC

Re: Coding: Fleeting Thoughts

Postby Ben-oni » Thu Jun 14, 2012 8:42 pm UTC

Sc4Freak wrote:I think as a software company, Microsoft is past the point of posting screenshots of their applications on the frontpage of their website. I don't think Office or Windows have screenshots on their frontpages either. :P

I've been following VS2012 reasonably closely and it's astounding just how much attention there is over something as trivial as casing of the main menu. It's ALLCAPS now instead of Title Case now... who cares? I'd rather that they focused on getting the rest of C++11 implemented! Bikeshedding in action?

If they can't get the simple things right, it doesn't bode well for the hard stuff.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Thu Jun 14, 2012 9:28 pm UTC

EvanED wrote:Since it's just a one-off thing, right now I just have this (actually incorrect because I remembered I need to null-terminate it just before leaving for the day; that leads to simplifications because I don't need to pass the size to the free function which means I don't need the lambda)

Ya, that is a mess. If you want to interface with C, just keep a C++ struct around that owns the memory.
std::vector<const char*> foo; &foo.front() gives you the char const* const* argv you want. Tossing a nullptr on the end is trivial. Loading it with char const*s from whereever is trivial.

Now, all you need is a seperate source of const char*s -- std::string::c_str() does exactly that. Keep a vector of the things that own the individual buffers (with move semantics, this is even pretty darn efficient! Prior to move semantics, a deque would have been advised), then populate your C-facing std::vector from it.

It is extremely clear who owns what memory as it is all stored in an RAII structure. The C-facing portion is just gloss on the action vector of strings, which is probably what you want. The overhead is on the order of a handful of bytes per string, which is what you pay when you call malloc or new anyhow. And if you really, really want compact memory, you can build a single memory buffer (std::string) with null seperators in it and record offsets and after that buffer is done, shove it all into a single std::vector< const char *> and your public interface is unchanged, and memory overhead just plummited (not that you should care).
But it's more than that. Hoping that they'll change the menus is more realistic than hoping they'll implement more C++11; the actual work would probably take someone who knows what they're doing 5 minutes plus whatever testing they have to do. Implementing, say, variadic templates is asking way way more of them. So it's also a case of "focus on the battles you may be able to win."

No, reworking the menus doesn't take 5 minutes. It takes talking with stakeholders about changing the application style from top to bottom, changing translation strings for multiple languages, doing a QA pass to check that everything still fits and looks right, and convincing people that doing this is worthwhile. Adding a C++11 feature can be done by a single developer over a weekend, and if that developer does it right its impact can be minimized. Now, it needs to be tested and validated and determine if it is worth the risk (or the original cost to implement), but there are in a sense fewer stakeholders and fewer reasons not to implement a C++11 feature than there are reasons not to change menus back.

C++0x features just require QA and Development effort. Changing the look of the application requires many more folk to get on board.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
sourmìlk
If I can't complain, can I at least express my fear?
Posts: 6393
Joined: Mon Dec 22, 2008 10:53 pm UTC
Location: permanently in the wrong
Contact:

Re: Coding: Fleeting Thoughts

Postby sourmìlk » Thu Jun 14, 2012 10:14 pm UTC

Then why haven't they implemented more C++11 features. I have found tons of uses for variadic templates, type traits, etc., some of which aren't implemented on MinGW. I'd at least like a backup until they get around to it :(
Terry Pratchett wrote:The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Thu Jun 14, 2012 11:01 pm UTC

Yakk wrote:
But it's more than that. Hoping that they'll change the menus is more realistic than hoping they'll implement more C++11; the actual work would probably take someone who knows what they're doing 5 minutes plus whatever testing they have to do. Implementing, say, variadic templates is asking way way more of them. So it's also a case of "focus on the battles you may be able to win."

No, reworking the menus doesn't take 5 minutes. It takes talking with stakeholders about changing the application style from top to bottom, changing translation strings for multiple languages, doing a QA pass to check that everything still fits and looks right, and convincing people that doing this is worthwhile.

I did say the "actual work". You still have to talk with the stakeholders and convince people that doing it is worthwhile and then do QA for the C++11 feature, which is why I didn't count that time. The latter especially would take far more effort for the C++11 feature than changing the menu text.

Take r-value references. (They've got that one.) Not only do you have to go write the compiler portion to deal with && and stuff, now you also have to go look at your STL implementation and figure out where all to put it. I wouldn't be at all surprised if they wrote thousands of tests for things impacted by that feature. A thousand tests is one test a minute for two eight-hour days. Now, rvalue references are probably one of the more wide-impact features, but I still think it's absurd to say that the effort is similar. The one thing I'll grant you is that I forgot about all the non-C++ people who use VS.

And besides: in some sense, talking with the stakeholders is pretty much exactly what everyone who's complaining about the all-caps menu is trying to make MS do. :-)

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Thu Jun 14, 2012 11:05 pm UTC

I'd rather they spend that time talking with stakeholders about (say) getting macros and macro recording back in, or adding a new C++0x feature, than burning that time on the case of the menu text.

And most C++0x features aren't as broad in impact as move semantics. The foreach for syntax, lambda to function pointer, initializer lists, or even varardic templates don't require a complete sweep of how the entire language interacts with them. When you don't use them, they don't apply.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: Coding: Fleeting Thoughts

Postby Sc4Freak » Fri Jun 15, 2012 5:53 am UTC

On the topic of C++11, is the following legal C++11?

Code: Select all

auto x = [](bool b) {
    if (b) return 1;
    return 2;
};

It seems to compile in GCC but I was under the impression that you could omit the lambda return type only if the lambda body consisted of a single return statement. The above compiles in GCC but not MSVC, but the below compiles in both:

Code: Select all

auto x = [](bool b) -> int {
    if (b) return 1;
    return 2;
};

Who is right according to the C++11 standard? I've seen both usages and I've been wondering whether to tell people off for it, but I've heard conflicting answers either way... :?

jareds
Posts: 436
Joined: Wed Jan 03, 2007 3:56 pm UTC

Re: Coding: Fleeting Thoughts

Postby jareds » Fri Jun 15, 2012 8:27 am UTC

Sc4Freak wrote:Who is right according to the C++11 standard? I've seen both usages and I've been wondering whether to tell people off for it, but I've heard conflicting answers either way... :?

You are more right. Omitting the lambda return type is always legal per se, but unless the body is a single return statement the return type is implicitly void. Thus, your first example is illegal. On the other hand, you can also omit the return type with any sort of lambda body that doesn't return a value.

elminster
Posts: 1560
Joined: Mon Feb 26, 2007 1:56 pm UTC
Location: London, UK, Dimensions 1 to 42.
Contact:

Re: Coding: Fleeting Thoughts

Postby elminster » Fri Jun 15, 2012 11:15 am UTC

EvanED wrote:I haven't used it, but from the couple screenshots I'm not quite sure what you mean. AT LEAST ASIDE FROM THE MENU NAMES.
Well, all the icons are more square. The icons look a little smaller. Almost everything is one of about 5 colours. I don't know really, the aesthetics just feels like windows 3.1.
Photoshop is similar, but the icons are slightly more rounded, natural and detailed. There's clearer separation between sections is more clear. It looks modern.
I don't really care that much about the styling, we started using VS 2012 for the C++11 features. Other than compiler compatibility, there's little reason not to use C++11.
EvanED wrote:Hmm, I do sorta see your point. Though if I'd hazard a guess, I'd almost say those other things you mention at least are used too commonly to be worth much space on the menu bar considering that I suspect most people know and use the keyboard shortcuts for them. (Though I do tend to use the save-all from the toolbar.)
I guess. I can see the reasoning in that respect. Given that for every solution you'll very most likely be making at least 1 project.
Image

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Fri Jun 15, 2012 12:09 pm UTC

Sc4Freak wrote:On the topic of C++11, is the following legal C++11?

Code: Select all

auto x = [](bool b) {
    if (b) return 1;
    return 2;
};

Illegal. This is legal:

Code: Select all

auto x = [](bool b) { return b?1:2; }

Lambdas without a return type are presumed void, unless they consist of only a single statement that returns non-void.

In short, there is a "single statement function" restriction on implicitly determining the return value of lambdas, and on constexpr functions. This probably isn't for any serious technical reason, but rather to make things a tad bit easier for the compiler writers who already have a boatload of work to do to get C++0x support working.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Fri Jun 15, 2012 5:02 pm UTC

Yakk wrote:This probably isn't for any serious technical reason, but rather to make things a tad bit easier for the compiler writers who already have a boatload of work to do to get C++0x support working.

<troll> I thought one developer could implement most C++11 features in a weekend. </troll> :wink:

Note that there is something similar like this, like with the RVO where a compiler may be able to perform RVO with one return statement but not with multiple ones.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Fri Jun 15, 2012 5:36 pm UTC

Rant:

Screw anti-patterns, I'm doing what works. They may not be perfect, but we can argue about how practical versus how pure they are all year long, and not a single line of code will be written. Sure, I have singletons. Sure, late static binding might be an anti-pattern. Sure, my "novel" way of allowing code extensions is misuse of OOP tools. But I don't care. It helps me do my job faster, better and safer, so argue all you want.

Cupcakes.
In Minecraft, I use the username Rirez.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Fri Jun 15, 2012 11:03 pm UTC

Screw cupckes, I'm having muffins!

I agree entirely with the rest of it though. 99% of my IRC bot's code gets stringified and eval'd for easy reloading, because making a tiny bugfix and having to restart the bot is such a pain. It's horrible and makes the error messages awful, but the other benefits outweigh that for now, so I stick to it.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sat Jun 16, 2012 12:48 am UTC

Steax wrote:Rant:

Screw anti-patterns, I'm doing what works. They may not be perfect, but we can argue about how practical versus how pure they are all year long, and not a single line of code will be written. Sure, I have singletons. Sure, late static binding might be an anti-pattern. Sure, my "novel" way of allowing code extensions is misuse of OOP tools. But I don't care. It helps me do my job faster, better and safer, so argue all you want.

Cupcakes.


Thing about anti-patterns is that they aren't necessarily the wrong solution. They often are, but it's not some sort of law of nature. Probably better to regard them as code smell than some sort of unholy sin.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Sat Jun 16, 2012 1:49 am UTC

Yakk wrote:How do you want to manage the lifetime of said buffers? Can you keep a (C++ class) whose job it is to RAII the lifetime?
Spoiler:
If so:

Code: Select all

struct c_args
{
  std::vector<std::string> original_buffer;
  std::vector<const char*> c_buffer;
  void make_c_buffer()
  {
    std::foreach( original_buffer.begin(), original_buffer.end, [&](std::string const& ) { c_buffer.push_back(s.c_str()); }
    c_buffer.push_back(nullptr);
  }
  c_args( std::vector<std::string> orig ): original_buffer(orig) { make_c_buffer(); }
  c_args( c_args const& other ): original_buffer( other.original_buffer) { make_c_buffer(); }
  c_args( c_args&& other ): original_buffer(std::move(other.original_buffer) { make_c_buffer(); other.c_buffer.clear(); }
  char const*const* get_c_buffer() const { return &c_buffer.front(); }
  size_t get_c_length() const { return c_buffer.size(); }
};

FWIW, here's my cleaned-up version: http://pastebin.com/kRSQz31a (It's amazing how much longer something becomes when you insert line breaks and comments and stuff :-)). I also changed using a foreach with a push_back inside to a transform with an inserter.

Thanks for the idea to use the std::strings as a container.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests