tag:blogger.com,1999:blog-376423286598101560.post5952079484031757023..comments2022-12-04T18:32:09.925-08:00Comments on xemdetia: "How Do I Get C Namespaces?", "How do I get Python Slices in C?" and other questionsxemdetiahttp://www.blogger.com/profile/14806502164720090302noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-376423286598101560.post-48954603114715417252012-09-05T08:42:37.772-07:002012-09-05T08:42:37.772-07:00I see not only in codecademy you write a ton. I le...I see not only in codecademy you write a ton. I left you a feedback there, if you wan't to view it.Zack Yovelhttps://www.blogger.com/profile/01495299149483743528noreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-50885104163766719212012-08-16T07:39:40.854-07:002012-08-16T07:39:40.854-07:00Similar article on namespaces subject: http://ejrh...Similar article on namespaces subject: http://ejrh.wordpress.com/2012/01/24/namespaces-in-c/bialixhttps://www.blogger.com/profile/03276301722234350242noreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-29351083642687080432012-07-05T10:47:51.063-07:002012-07-05T10:47:51.063-07:00Apparently you've never heard of building libr...Apparently you've never heard of building libraries for other's use, or even working with a team in general. God forbid you actually build something useful enough for someone else to use.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-13580258243714432402012-07-04T01:56:47.708-07:002012-07-04T01:56:47.708-07:00I made test of compiling the example for AVR with ...I made test of compiling the example for AVR with avr-gcc and found that generated code did not use function pointers at all, it called functions directly. I'm sure this is because static const is used: I know that avr-gcc (or maybe just gcc) is very good in optimizing (read: inlining) static functions.bialixhttps://www.blogger.com/profile/03276301722234350242noreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-18405706996261834082012-07-02T09:35:37.802-07:002012-07-02T09:35:37.802-07:00This was my assumption and I am still trying to ma...This was my assumption and I am still trying to make sure I do a proper testing of all possible optimizations I could miss out on as well as other failures of my dumb technique. I had the assumption since it was a const value that a sensible compiler would just do a replacement like your code sample suggests.<br /><br />I hope to finish my analysis soon and I'll post another update soon but I am trying to really do a fair and proper test.<br /><br />Thanks for your comment,<br /><br />xemdetiaxemdetiahttps://www.blogger.com/profile/14806502164720090302noreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-46276383151108777972012-07-02T08:07:32.234-07:002012-07-02T08:07:32.234-07:00> vastly greater performance
Not unless by &qu...> vastly greater performance<br /><br />Not unless by "vastly" you mean "not at all". Compile with -O3, look at the assembly:<br /><br />https://gist.github.com/3033687#file_test_o3.s<br /><br />Line 11 and 12 are equal. Thus is the power of const and -O3.<br /><br />HrabanHrabannoreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-29607481219817274802012-07-01T13:32:38.703-07:002012-07-01T13:32:38.703-07:00I kinda have the same background. My first self-ta...I kinda have the same background. My first self-taught languages were php and...actionscript 3. While I quickly understood them, I never got the mastery I got when I was taught the C in computer classes: prototypes, return values,...<br /><br />Where php and as3 let me do multiple mistakes (and were mostly complaining about scope or references to non-existing variables), the C language was HARD with me, always complaining about types (like casting the void * returned by calls to dlsym to a pointer to function), undefined references, uninitialised variables, unused return types, unchecked return values,...<br /><br />I was mallocing my own memory, I was juggling with my own pointers, I was playing with my own bytes,... And when your school forbids you to use printf() for one year to make sure you know how to use write(), you're so close to the kernel you could smell it.<br /><br />And to me, that's what C is about: pure control. Unfortunately, even CPP doesn't have this level of control and everything just looks like "C for people who want it easy". No, I don't want a "new", I want to control my memory and be able to check if something went wrong so I can go another branch, not use exceptions to rewind my stack. Why do I need to catch an exception for memory allocation failure when I can just check if (ptr == NULL)?<br /><br />I don't blame dynamic languages, nor do I hate them.<br />I love php, I love javascript (though I still don't get some of its memory/scope use and miss pointers sometimes...),... I just know that I don't have the same level of control, I know I have it easy.<br /><br />And because my school also taught me about rigor and code cleanliness (and especially because I'm a geek/nerd), I want to have control everywhere, I want to KNOW what my application is doing underneath, I want to know I'm out of bounds, I want to be sure I get a specific type before sending it to another function,...<br /><br />What's not to love about C? :)Joshua Guthriehttps://www.blogger.com/profile/00474189030726819002noreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-37427541090946214532012-07-01T10:36:20.836-07:002012-07-01T10:36:20.836-07:00Thank you for your kind post. I've gotten a lo...Thank you for your kind post. I've gotten a lot of negative feedback that I hopefully can address sooner rather than later. Still though I think I made the point I wanted to make, and getting trying to address the misconceptions I always see come up from people who learned a dynamic language first.xemdetiahttps://www.blogger.com/profile/14806502164720090302noreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-21567135624208917552012-07-01T10:35:21.209-07:002012-07-01T10:35:21.209-07:00Good idea, why have namespaces if we can just type...Good idea, why have namespaces if we can just type "using namespace Bar" to have everything in the global scope?<br /><br />Now I understand why my school CPP classes forbade us for ever using "using namespace". And I get Torvalds and his ire for CPP even more...Joshua Guthriehttps://www.blogger.com/profile/00474189030726819002noreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-82347608825859934042012-07-01T10:31:59.119-07:002012-07-01T10:31:59.119-07:00I never understood this whole concept of "pro...I never understood this whole concept of "prohibiting access to functions":<br /><br />You are writing the code, you should KNOW when a function is or is not called, you should be able to limit the instances in which a function is called, all because the code is yours.<br /><br />Maybe it rings true in a paradigm like CPP (because object B is not supposed to call a function from object A etc...), but the same reasoning happens: if object B calls a prohibited functions from object A in your code, you will never compile. So why in the first place did you call this function?<br /><br />So really, enlighten me (no joke, I really want to understand this), why would you need to prohibit access to a function when YOU are the one deciding which function is called and when? It just bugs me, and strikes me as bad programming.Joshua Guthriehttps://www.blogger.com/profile/00474189030726819002noreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-84056588226472339952012-07-01T10:27:15.054-07:002012-07-01T10:27:15.054-07:00Thank you.
I've been using C for two years no...Thank you.<br /><br />I've been using C for two years now and despite all my love for javascript, it's still my "de facto" language. Despite everything people find "flawed" in it, I still love it.<br /><br />- No support for strings? I don't need strings when I can manipulate data to the byte.<br />- I need to malloc stuff myself? Good, I'll then be sure I use the right data when juggling my pointers around.<br />- No namespaces? I coded a whole shell and never found myself needing namespaces.<br /><br />C is not "rocket science", people have been so used to scripting languages that they don't understand what it all boils down to, the same way people that (ab)use jQuery don't know what "document.selectElementById()" or even the concept of DOM nodes really mean... (And I've found the harsh way that there are a lot of people like this...)<br /><br />C does what you tell it to do, C will be strict in asking you to not mix types, C will make sure mostly everything is okay before being given a chance to run, C will talk to your kernel directly,...<br /><br />To C is to Love =)Joshua Guthriehttps://www.blogger.com/profile/00474189030726819002noreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-67203025695528172382012-07-01T07:12:30.875-07:002012-07-01T07:12:30.875-07:00I liked your idea. It's an option; "using...I liked your idea. It's an option; "using namespace Food;" is no good anyway.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-48250493501370742232012-07-01T05:18:42.652-07:002012-07-01T05:18:42.652-07:00The critical feature of namespaces is not granting...The critical feature of namespaces is not granting access to some functions, but prohibiting access to others. If a namespace/module is not imported, I cannot call it, which greatly aids my reasoning about what could be going wrong in my code.<br /><br />Your dumb idea does not have this feature. It looks like namespaces, while providing none of the benefits of namespaces save for looking like them.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-376423286598101560.post-21382995304196384612012-06-30T22:38:52.939-07:002012-06-30T22:38:52.939-07:00Your idea of using a struct and function pointers ...Your idea of using a struct and function pointers to simulate C++ namespaces at the syntactic level is Worse Than Useless. Yes, it lets you write Bar.foo() instead of Bar_foo(), but so what? By not being scared of underscores, I get the exact same amount of code readability and vastly greater performance (because the code doesn't have to indirect through a pointer every time it makes a function call).<br /><br />Plus, you're not even fixing the original problem with Bar_foo(), which is that long_names_are_cumbersome(). "Bar.foo()" might *look* more C++ish, but you can't do the equivalent of "using namespace Bar" to bring foo() into scope; you must refer to it as "Bar.foo()" on every invocation. Again, there's no savings versus simply referring to it as "Bar_foo()" on every invocation.Anonymousnoreply@blogger.com