Re: Looking at self = [super init].
While in principle machine code implementations of subroutines can return from several different places, in practice they don't. Rather the compiler's code generator emits a branch instruction to the end of the subroutine, there there is an epilog. There are many good reasons for returning from the middle in certain specific cases; what if the only epilog you need is an rts? Branching to the epilog could cause a cache miss. I expect the compiler developers know all about this but don't typically avail themselves of it because writing compilers is difficult. To be clear, the following source code: - (id) init { if ( self == [super init] ) return nil; // lots of code goes here return self; } ... is implemented as something like this, but in machine code: - (id) init { id result; if ( self == [super init] ){ result = nil; goto epilog; } // lots of code goes here result = self; epilog: return result; } Michael David Crawford, Consulting Software Engineer mdcrawf...@gmail.com http://www.warplife.com/mdc/ Available for Software Development in the Portland, Oregon Metropolitan Area. On Fri, May 29, 2015 at 6:25 PM, Graham Cox graham@bigpond.com wrote: On 30 May 2015, at 3:22 am, Alex Zavatone z...@mac.com wrote: // We don't care if this gets long. My take is that you're rewriting a well-recognised idiom to solve a non-existent problem. The well-recognised idiom makes it easy to verify it's correct. Hiding a different construct inside a macro obscures that, making it harder to verify the code. It's not wrong exactly, just harder to see at a glance that it's right. The non-existent problem you're trying to solve is that the gap between a pair of braces could get large. So what? Early returns can be another source of bugs, so structural purists would tell you that you shouldn't do that. Sometimes I think it's justified, but not usually worthwhile. Another religious issue is whether matching braces should line up or not. Personally I prefer that they do, at the cost of an extra line. Because you aren't doing that, your long distance between braces is bothering you, because you're losing track of where it started (I assume that's why it's bothering you). If you line up the braces that is much less of an issue. Source code is for humans, so it should be as readable as you can possibly make it. Macros often hinder that. Unaligned braces hinder that. Multiple statements per line hinder that. Factoring code helps, so I'd suggest that's the better way to solve this. (and it's also beneficial when it comes to making sure that -initWithCoder: and other initializers that don't correctly follow the designated initializer rule can get access to your common initialization. While this is rarely a problem, I did notice that the recent change to encourage the use of -initWithCoder: for unpacking NSViews from a nib breaks this long-standing rule and so a common init method that both can call is a simple workaround). --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/mdcrawford%40gmail.com This email sent to mdcrawf...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to get bold and plain fonts?
A quick test (in Swift no less) suggests to me that this function just doesn’t work (TM). I get non-zero results for these 13 flag combinations (count of fonts + mask) and zero results for every other one of the 4096 combinations. 141 NSItalicFontMask 259 NSBoldFontMask 61 NSItalicFontMask + NSBoldFontMask 6 NSExpandedFontMask 3 NSExpandedFontMask + NSBoldFontMask 43 NSCondensedFontMask 12 NSCondensedFontMask + NSItalicFontMask 22 NSCondensedFontMask + NSBoldFontMask 6 NSCondensedFontMask + NSItalicFontMask + NSBoldFontMask 30 NSFixedPitchFontMask 11 NSFixedPitchFontMask + NSItalicFontMask 11 NSFixedPitchFontMask + NSBoldFontMask 5 NSFixedPitchFontMask + NSItalicFontMask + NSBoldFontMask I think you’re probably better off calling availableFontFamilies then iterating those with availableMembersOfFontFamily: and picking out the ones you want from there. That’s probably better anyway as it will give you all the font families which have both a plain and a bold option which sounds like what you might want. I’d try it out but I’ve exhausted my Swift-fu for the day. On 31 May 2015, at 10:42, Graham Cox graham@bigpond.com wrote: I’m using -[NSFontManager availableFontNamesWithTraits:] and I want to get the names of all of the fonts that have both a regular (plain) and bold option. I’ve tried various things, but this seems like it should work: NSArray* fonts = [[NSFontManager sharedFontManager] availableFontNamesWithTraits:NSBoldFontMask | NSUnboldFontMask]; Except it returns no results. According to the docs if I pass 0 for traits, it should return all the plain fonts, and it’s equivalent to NSUnboldFontMask | NSUnitalicFontMask. That returns no results. If I set it to a single value, such as NSBoldFontMask, I get all the bold fonts, but no plain ones. I also tried NSBoldFontMask | NSUnboldFontMask | NSUnitalicFontMask, but that returns no results. What’s the magic traits mask I need? Seems like it should be a simple thing to get plain + bold, except that a bit mask doesn’t really work to express this, because there’s no value for “plain” - plain is the absence of any other trait. So how do I ask for it? —Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org This email sent to r...@rols.org ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to get bold and plain fonts?
On 31 May 2015, at 1:44 pm, Kyle Sluder k...@ksluder.com wrote: Here, you're asking for all fonts that consider themselves to be both bold and unbold. This set is going to be empty (unless you have a particularly broken font installed). Yeah, I just realised that though of course you’re adding trait masks together with OR, the value is interpreted as AND, so A ~A = 0. Seems as if there’s no way to express what I want with this. It’s a terrible API anyway. If you want to query for fonts with certain traits, you're much better off using NSFontDescriptor. I’ll look at that as a better alternative. On 31 May 2015, at 1:27 pm, Roland King r...@rols.org wrote: A quick test (in Swift no less) suggests to me that this function just doesn’t work (TM). Looks that way :( Thanks both. —Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Looking at self = [super init].
Actually, i was typing by habit and included == instead of = by mistake. So, while you answered the question, you may have answered the wrong question. The question is not for if ( self == [super init]) It's if ( self = [super init]) How does that change your answer? On May 30, 2015, at 6:08 PM, Michael David Crawford wrote: While in principle machine code implementations of subroutines can return from several different places, in practice they don't. Rather the compiler's code generator emits a branch instruction to the end of the subroutine, there there is an epilog. There are many good reasons for returning from the middle in certain specific cases; what if the only epilog you need is an rts? Branching to the epilog could cause a cache miss. I expect the compiler developers know all about this but don't typically avail themselves of it because writing compilers is difficult. To be clear, the following source code: - (id) init { if ( self == [super init] ) return nil; // lots of code goes here return self; } ... is implemented as something like this, but in machine code: - (id) init { id result; if ( self == [super init] ){ result = nil; goto epilog; } // lots of code goes here result = self; epilog: return result; } Michael David Crawford, Consulting Software Engineer mdcrawf...@gmail.com http://www.warplife.com/mdc/ Available for Software Development in the Portland, Oregon Metropolitan Area. On Fri, May 29, 2015 at 6:25 PM, Graham Cox graham@bigpond.com wrote: On 30 May 2015, at 3:22 am, Alex Zavatone z...@mac.com wrote: // We don't care if this gets long. My take is that you're rewriting a well-recognised idiom to solve a non-existent problem. The well-recognised idiom makes it easy to verify it's correct. Hiding a different construct inside a macro obscures that, making it harder to verify the code. It's not wrong exactly, just harder to see at a glance that it's right. The non-existent problem you're trying to solve is that the gap between a pair of braces could get large. So what? Early returns can be another source of bugs, so structural purists would tell you that you shouldn't do that. Sometimes I think it's justified, but not usually worthwhile. Another religious issue is whether matching braces should line up or not. Personally I prefer that they do, at the cost of an extra line. Because you aren't doing that, your long distance between braces is bothering you, because you're losing track of where it started (I assume that's why it's bothering you). If you line up the braces that is much less of an issue. Source code is for humans, so it should be as readable as you can possibly make it. Macros often hinder that. Unaligned braces hinder that. Multiple statements per line hinder that. Factoring code helps, so I'd suggest that's the better way to solve this. (and it's also beneficial when it comes to making sure that -initWithCoder: and other initializers that don't correctly follow the designated initializer rule can get access to your common initialization. While this is rarely a problem, I did notice that the recent change to encourage the use of -initWithCoder: for unpacking NSViews from a nib breaks this long-standing rule and so a common init method that both can call is a simple workaround). --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/mdcrawford%40gmail.com This email sent to mdcrawf...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com This email sent to z...@mac.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
How to get bold and plain fonts?
I’m using -[NSFontManager availableFontNamesWithTraits:] and I want to get the names of all of the fonts that have both a regular (plain) and bold option. I’ve tried various things, but this seems like it should work: NSArray* fonts = [[NSFontManager sharedFontManager] availableFontNamesWithTraits:NSBoldFontMask | NSUnboldFontMask]; Except it returns no results. According to the docs if I pass 0 for traits, it should return all the plain fonts, and it’s equivalent to NSUnboldFontMask | NSUnitalicFontMask. That returns no results. If I set it to a single value, such as NSBoldFontMask, I get all the bold fonts, but no plain ones. I also tried NSBoldFontMask | NSUnboldFontMask | NSUnitalicFontMask, but that returns no results. What’s the magic traits mask I need? Seems like it should be a simple thing to get plain + bold, except that a bit mask doesn’t really work to express this, because there’s no value for “plain” - plain is the absence of any other trait. So how do I ask for it? —Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to get bold and plain fonts?
On Sat, May 30, 2015, at 09:42 PM, Graham Cox wrote: I’m using -[NSFontManager availableFontNamesWithTraits:] and I want to get the names of all of the fonts that have both a regular (plain) and bold option. I’ve tried various things, but this seems like it should work: NSArray* fonts = [[NSFontManager sharedFontManager] availableFontNamesWithTraits:NSBoldFontMask | NSUnboldFontMask]; Here, you're asking for all fonts that consider themselves to be both bold and unbold. This set is going to be empty (unless you have a particularly broken font installed). Except it returns no results. According to the docs if I pass 0 for traits, it should return all the plain fonts, and it’s equivalent to NSUnboldFontMask | NSUnitalicFontMask. That returns no results. This is a known bug. If you want to query for fonts with certain traits, you're much better off using NSFontDescriptor. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to get bold and plain fonts?
On 31 May 2015, at 1:44 pm, Kyle Sluder k...@ksluder.com wrote: you're much better off using NSFontDescriptor. So here’s what I’m trying to do. I have a “simple” UI that, among many other things, allows the user to choose a font for various things in a display. I want to keep the set of choosable fonts down to something ”reasonable” rather than stacking it with every possible font. I’m using a pop-up button to present the fonts, so I want to avoid hierarchical menus which don’t really work very well in a pop-up button. Looking at what NSFontManager provides, I can read in entire font collections that match what the user has set up in the Fonts panel, and that gave me the idea to actually look for a custom collection that has a particular name - I can document that creating a collection with such-and-such a name and populating it will show only those fonts the user added to the custom collection. That’s a nice way to limit the choice, because the user can set it up themselves how they want. But I also need a fallback for when this hasn’t been done, so I thought I’d use the “User” collection and the Favourites” collection (the “User” collection’s name is localized I guess - in mine it’s “English”, but the actual collection name is “com.apple.UserFonts”). When I ask NSFontManager for the descriptors in a collection, I get a very large number, one for each variant of a given font. I’d like to be able to collapse this down to match what the Font Panel displays - it only displays a single entry for each font family, then breaks that down using separate columns. I’d like my menu to match the first column, showing only the family names. Then I might offer only the plain and bold variants within that family. What I’m not clear about is how to go from a list of NSFontDescriptors to a common family that groups those descriptors. There seem to be many methods that expand a descriptor or family, but none that collapse a set of descriptors to a family. I’m happy to perform this collapsing myself, I’m just not sure how I should do it. A NSFontDescriptor doesn’t have a ‘family’ property, and the postscript name property is the full description of course. I could attempt to parse that to find the common root but I’m not sure if that’s reliable. It seems as if it could be, based on the fonts I have installed, but that doesn’t mean it is. So, TL;DR: how do I find the Font Family name(s) corresponding to an arbitrary list of NSFontDescriptors from a font collection? —Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
[PSA] OSStatus.com — Error code lookup
I can't tell you how many times over the years I've been frustrated by having to manually search multiple frameworks' header files to look up what the symbol or description for an error code value was. (I know 'macerror' exists, but I have never had any luck with it. I consider it useless.) I finally got fed up, wrote some code, and made a website. So, here's v1. http://www.osstatus.com/ I hope someone besides me finds it useful. ;-) -- Seth Willits ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [PSA] OSStatus.com -- Error code lookup
May I Bear Your Firstborn? Michael David Crawford, Consulting Software Engineer mdcrawf...@gmail.com http://www.warplife.com/mdc/ Available for Software Development in the Portland, Oregon Metropolitan Area. On Sat, May 30, 2015 at 9:38 PM, Seth Willits sli...@araelium.com wrote: I can't tell you how many times over the years I've been frustrated by having to manually search multiple frameworks' header files to look up what the symbol or description for an error code value was. (I know 'macerror' exists, but I have never had any luck with it. I consider it useless.) I finally got fed up, wrote some code, and made a website. So, here's v1. http://www.osstatus.com/ I hope someone besides me finds it useful. ;-) -- Seth Willits ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/mdcrawford%40gmail.com This email sent to mdcrawf...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
[OT] Computer Employer Index
I am building a list of links directly to the Jobs or Careers sections of computer employer websites. Not just for coding jobs but also hardware engineering, QA, project management, technical sales and the like. http://www.warplife.com/jobs/computer/ So far I've done this mostly in a very painfully manual way however I am developing some automated tools. There is no charge for a listing there, nor will there ever be. Please do not be dismayed if I do not yet list your company, just mail your homepage URL - offlist - to mdcrawf...@gmail.com I am not aiming to make money from this. I'm doing it as a public service to the community. The Santa Cruz County, California page explains why I started it way back in 1997; I little over a year ago I decided to work towards a global index. The best coverage so far is for Portland and Seattle. The San Luis Obispo page does not have many entries but because SLO doesn't have much tech that list can be considered reasonably complete. I also cover San Francisco, Boston, New York City, London and Berlin. There is also a remote work page. I have a great many links that I have not posted yet. I generally post a page for a new location once I have enough links that I can make a splash by announcing that specific page. You could help a lot of people out were you to pass the URL onto those who you genuinely feel would be interested in or would benefit from it. Yours, Mike Michael David Crawford, Consulting Software Engineer mdcrawf...@gmail.com http://www.warplife.com/mdc/ Available for Software Development in the Portland, Oregon Metropolitan Area. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com