When both ‘true’ and ‘false’ are right

I ran into very interesting logic issue. Probably if someone asks me what case it was, then I would not be able to recall this, because it’s subtle ( but simple ).

bool vaFacebookAPI::HandleResponse(zuint32 what, zRecord *record, zRecord *current, zRecord *previous)
{
    bool isHandled = true;

    if (record == nullptr || current == nullptr) {

        // You can think of this as 'handled' or 'not handled' depending on
        // how you think. But architecturally it should be treated as 'not handled'
        return false; // ๐Ÿ‘ˆ๐Ÿผ This case 
    }

    ...
}

1. You can think that it can return ‘true’, because such case is considered and you decided not to do anything. So, It’s handled as such. So, it’s right to be ‘true’.

2. You can think it it can return ‘false’, because for that case nothing is processed and just returns. So, you can regard it as ‘not handled’. So, ‘false’ is correct.

Interesting, isn’t it?
One logic, depending on how you think it can be thought as ‘true’ and ‘false’

So, true is true, and false is also true. ๐Ÿ˜‰

deprecation of C++ style for loop and its replacements are…

New Features in Swift 2.2

Swift… ์ด๊ฑฐ ์ฐธ..
Telestream์—์„œ ์ผ์„ ํ•œ ์ด๋ž˜, ์ œ๋Œ€๋กœ Objective-C/Cocoa์—์„œ ์ƒˆ๋กœ ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ์‹œ๋„ํ•˜๊ฑฐ๋‚˜, ์‹ฌ์ง€์–ด Swift๋ฅผ ๊ณต๋ถ€ํ•  ์งฌ์ด ์—†์—ˆ๋‹ค. C#/.NET์ด๋‚˜ C++๋„ ๋งˆ์ฐฌ๊ฐ€์ง€…
์ด์ „ ํšŒ์‚ฌ๋“ค์—์„  ํ‡ด๊ทผํ•˜๊ณ ์„œ๋„ ๋‹น์—ฐํžˆ ํ–ˆ๊ณ , ํšŒ์‚ฌ ๋‚ด์—์„œ๋„ ํ•  ์ผ ๋‹คํ•˜๊ณ , ์ถ”๊ฐ€๋กœ ๋” ์•Œ์•„๋ณด๊ณค ํ–ˆ๋Š”๋ฐ, ๋„๋Œ€์ฒด ์ด ํšŒ์‚ฌ์—์„ …
Cocoa์— ๋Œ€ํ•ด์„œ ์•Œ๊ณ  ์žˆ๋˜ ๊ฒƒ๋„ ๊นŒ๋จน๊ณ . ๊ทธ๋ž˜์„œ๋“ค ๋ฏธ๊ตญ ์• ๋“ค์ด ์ด๋Ÿฐ ํšŒ์‚ฌ์— ์ง€์›์„ ์•ˆํ•˜๋‚˜๋ณด๋‹ค.

์•„๋ฌดํŠผ ํˆฌ๋œ๋Œ€๋Š” ๊ฒƒ์€ ์ด๋งŒํ•˜๊ณ ..
๋‚œ ย Swift๊ฐ€ ๋„๋Œ€์ฒด ๋งˆ์Œ์— ๋“ค์ง€ ์•Š๋Š”๋‹ค.
Swift๊ฐ€ ํ›„์ ธ์„œ๊ฐ€ ์•„๋‹ˆ๋ผ, ์ด๊ฑด ์ˆœ์ „ํžˆ ๋งˆ์ผ€ํŒ…์— ์˜ํ•œ ๊ฒƒ์ด๋ž€ ์ƒ๊ฐ์ด ๋“ค๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
GNU์˜ Objective-C ์ปดํŒŒ์ผ๋Ÿฌ๋ฅผ ๋“ค์ถฐ๋ณธ ์‚ฌ๋žŒ๋“ค์€ ์–ผ๋งˆ๋‚˜ ๊ฐ„๋žตํ•˜๊ฒŒ Objective-C๊ฐ€ ๋งŒ๋“ค์–ด์ ธ ์žˆ๋Š”์ง€ ์•ˆ๋‹ค. C++์ชฝ์€ ๋ณ„ ์ด์ƒํ•œ ์ง“์„ ํ•ด์„œ๋ผ๋„ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜๋Š”๋ฐ, ๊ตณ์ด ๋ช‡๊ฐ€์ง€ Objective-C์˜ ๋‹จ์ ์„ ๋“ค์ถฐ์„œ ๊ทธ๊ฑธ Swift๋ฅผ ํ•ฉ๋ฆฌํ™”ํ•˜๋Š” ๊ฑด ๋ญํ•˜์ง€ ์•Š๋‚˜? ๋ฌธ์ œ๊ฐ€ ์žˆ์œผ๋ฉด ๊ณ ์น˜๋ฉด ๋˜์ง€ ์•Š๋‚˜?

๋”๊ตฐ๋‹ค๋‚˜ Swift๋Š” ํ—ท๊ฐˆ๋ฆฌ๋Š” ๋ฉด์ด ๋งŽ๋‹ค. ์ƒˆ๋กœ ์–ธ์–ด๋ฅผ ๋ฐฐ์šฐ๋Š” ์–ด๋ฆฐ ํ•™์ƒ๋“ค์ด์•ผ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ, ๋‚ด๊ฒ ์ด Swift๋Š” ์–ด๋–ค ๋ฉด์—์„  Pascal, ์–ด๋””์„  C, ์–ด๋””์„  Perl ๊ฐ™์€ ๋Š๋‚Œ์ด ๋“ ๋‹ค. Python์„ ํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์€ Python ๊ฐ™์€ ๋ถ€๋ถ„๋„ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค.
์ผ๋‹จ ๋ชจ๋“œ๊ฐ€ Pascal ๋ชจ๋“œ๋กœ ๋ฐ”๋€Œ๋ฉด Pascal ๋‹ค์›Œ์•ผ ํ•˜๊ณ , C๋กœ ๋ฐ”๋€Œ๋ฉด C ๋‹ค์›Œ์•ผ ํ•œ๋‹ค. ๊ทธ๋ž˜์•ผ ๊ธฐ์–ตํ•˜๊ธฐ๋„ ์ข‹๊ณ  ๊ทธ๋ ‡์ง€. ์ด๊ฑด ์ˆœ์ „ํžˆ ์žกํƒ•๊ฐ™์€ ๋Š๋‚Œ์ด์–ด์„œ, ๊ฐ„๋งŒ์— Swift ๋ฌธ์„œ๋ฅผ ์ฝ์–ด์„œ ์ตํ˜€ ๋‘์–ด๋„ ๋‚˜์ค‘์— ๊ธฐ์–ต์ด ์ž˜ ์•ˆ๋‚œ๋‹ค. ์™œ? ํŒŒ์Šค์นผ ๊ฐ™์œผ๋ฉด ์ญ‰ ํŒŒ์Šค์นผ ๊ฐ™์•„์•ผ ํ•˜๋Š”๋ฐ, ์–ด๋Š ์ˆœ๊ฐ„ Perl ๊ฐ™๋‹ค๊ฑฐ๋‚˜ ๊ทธ๋Ÿฐ์‹์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

๊ทธ๋ฆฌ๊ณ  2.2์—์„œ ์ƒˆ๋กœ ๋‚˜์˜จ ๋ฌธ๋ฒ•์„ ๋ณด์ž.
๋‹ค์Œ์˜ ์ฝ”๋“œ๋ฅผ ๋ณด์ž

for var i = 0; i < 10; i++ {
    print(i)
}

์ด๊ฑธ ์ด์ œ ์—†์• ๊ณ  ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ฐ”๊พผ๋‹ค ํ•œ๋‹ค.

for i in 0 .. < 10 {
    print(i)
}

์ด๊นŒ์ง„ ์ข‹๋‹ค. Fast Enumeration ์Šคํƒ€์ผ์ด๋‹ˆ๊นŒ.

๊ทผ๋ฐ, ๋‹ค์Œ์„ ๋ณด์ž.

for i in (1...10).reverse() {
    print(i)
}

for i in 0.stride(to: 10, by: 2) {
    print(i)
}

์ €๊ฑฐ ๊ทธ๋ƒฅ (10…1)๋กœ ๋ชป ๋งŒ๋“œ๋‚˜? ๋ฌผ๋ก  reverse()๋„ ์ง€์›ํ•˜๋ฉด์„œ?
๋ญ ์ฒซ๋ฒˆ์žฌ ์˜ˆ๋Š” ๊ทธ๋ ‡๋‹ค์น˜์ž.
๋‘๋ฒˆ์žฌ ์˜ˆ..

์ €๊ฑฐ.. ์˜์–ด๊ฐ€ ๋ชจ๊ตญ์–ด์ธ ์‚ฌ๋žŒ์€ 0.stride(to..)๊ฐ€ ์™€ ๋‹ฟ์„์ง€ ๋ชฐ๋ผ๋„, ์™ธ๊ตญ์ธ๋“ค์—๊ฒ ๊ทธ๋ ‡์ง€ ์•Š๋‹ค. stride์˜ ๋œป์ด ๊ทธ๋‹ค์ง€ ๊ฐ•ํ•˜๊ฒŒ ๋‹ค๊ฐ€์˜ค์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
๋‹จ์–ด์˜ ๋œป์„ ์•„๋Š” ๊ฒƒ๊ณผ, ๊ทธ๊ฒƒ์ด ์–ผ๋งˆ๋‚˜ ๊ฐ•ํ•˜๊ฒŒ ๋‹ค๊ฐ€์˜ค๋Š๋ƒ๋Š” ๋‹ค๋ฅธ ๋ฌธ์ œ์ด๋‹ค.
stride?
Apple์˜ ์‚ฌ์ „ ์•ฑ์—์„œ ๋œป์„ ๋ณด์ž.
1. ์„ฑํผ ์„ฑํผ ๊ฑท๊ธฐ. ํ™œ๋ณด
2. ํ•œ๊ฑธ์Œ, ํ•œ๋‹ฌ์Œ.

์•„.. ์•ˆ๋‹ค๊ฐ€์˜จ๋‹ค.
์ด๋Ÿฐ๊ฒŒ ๋‚ซ์ง€ ์•Š๋‚˜?

for i in 0.increment(to: 10, by: 2) {
    print(i)
}

for i in 0.increment(to: 10, by: -2) {
    print(i)
}

๋‘๋ฒˆ์งธ ๊ฒƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋™์ผ ํ‘œํ˜„์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๊ฒ ๋‹ค.

for i in 10.decrement(to: 0, by: 2) {
    print(i)
}

Swift๋Š” ์ปดํ“จํ„ฐ ์–ธ์–ด์—์„œ์˜ cultural difference์™€ ์‚ฌ๋žŒ์ด ์“ฐ๋Š” ์–ธ์–ด์—์„œ์˜ cultural difference๋ฅผ ๊ณ ๋ คํ•˜์ง€ ์•Š๊ณ  ๋””์ž์ธ๋˜๋Š” ๋Š๋‚Œ์ด๋‹ค.
์ด๊ฑด ๋ฌธ์ œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋‚ด๊ฐ€ Swift๋ฅผ ์ข‹์•„ํ•˜์ง€ ์•Š๋Š” ๋ฌธ์ œ ์ค‘์˜ ํ•˜๋‚˜์ด๋‹ค.

Dialogue’s Guiding Principles, or a Healthy Hatred of OOP two chain links

Dialogue’s Guiding Principles, or a Healthy Hatred of OOP two chain links

Well, it will be interesting to read the post.
However, I found out that problems among US programmers in terms of C++ is that they follow C++ techniques or new syntax etc, which are just supplemental rather than keeping philosophy of OOP and meta-programming.
Syntax-sugar is good. But problems of C++ is that ( don’t misunderstand that. As you can see I’m a long-time C++ programmer and I liked its initial paradigm a lot. ) a lot of features have been added to C++ for the sake of convenience ( with difficulty of using it ) or more power. People, who just judge others’ knowledge on C++ just by asking terminology and features, thus missing core values, love to use any new features.
Knowing such things are good and beneficial, but not always.
I’ve worked on pSosystem at Samsung and other systems where the greatest and the latest C++ features were omitted intentionally for the purpose of the system or unintentionally (just old C++ compiler). If people just stick to the greatest and latest feature and when exposed to such system, they are embarrassed often.
So, I’m always in the attitude of choosing common ground, which maximizes compatibility of source code and your knowledge compatibility.

Anyway, folks. Knowing more terminology and new features will make look more knowledgeable person especially here in the US due to its culture, but actually it’s not. What is more important is to know why you need to use this or that, philosophy behind of a language you choose, etc.

Here I see Objective-C code which is not written by people who understand Objective-C philosophy. They argue that they know, but if you see such code, ou will be able to see that they don’t understand the philosophy.
They oppose Objective-C or any other language without understanding their philosophy. Criticism can be good only and only if people criticize after understanding philosophy or background history on why this language/system is designed as such.

So far, my experience here in the US is that when interviewers were too picky and just judges people by asking if the interviewee knows(memorizes) one thing, I usually found out that their source code were dirty and messy in every angle.
If an interviewee is not a liar or a salesperson who wants to sell himself rather than an engineer, they tend to memorize terminology etc. But if they are engineers, they know but at the moment of being asked, they may not answer the interviewers question. It’s not because they don’t know about the answer, but they can guess something else.

For example, I’ve been asked like “implement this thing using STL.”
Well, I use Win32 collection APIs, Cocoa/Core Foundation collection APIs and also STL. Also I use boost. They are similar. If you happen to use Win32 collection API for the week when you are interviewed, you can temporarily forget STL. But if you look up document, you can quickly write in STL. Then doesn’t he know the STL?

Here in the US, although they say they are Objective-C programmer, they write in C++ and STL mostly. So, they can remember STL syntax.

I’m different. When I implement Win32 code, I stick to Win32 stuffs mostly. When I implement Cocoa/Core foundation code, I stick to them.
If I need to implement something common code, which I may need to use on Window / Mac / iOS/ Unix, I write with pure C/C++/STL. Then, I can temporarily forget one syntax. But does it mean that I don’t know about it?

I’m versatile person. However, the way US people interview others are not like that and they stick to one thing and say they are “the other” programmer.

Another example is … I’m asked how to implement XOR in C++ while being asked about bit-wise operations. So, I told him it’s ^ operator.
He said “No.”
Actually in the conversation, he jumped from logical operation and bit-wise operation. So, I wonder why he said “No.”
Well, what he wanted “DeMorgan’s law” to express logical XOR.
Damn.. then he must be clear on that.
In Korea, DeMorgan’s law is taught in middle school. Everybody knows DeMorgan’s law. Well, actually what is taught here in the US are mostly taught in middle school or high school like calculus, probability etc. Well. some are taught in here too in high school. But compared to the level of things taught in Korea, well here.. I understand why Obama mentioned education in Korea, although I oppose to his intention.
Anyway, then he treated me like a person who doesn’t know C++.

What the..

LLVM based just-in-time compiler for C++

http://www.jyt.io/

Raw Key Code for Function Keys

I figure out key codes for function keys from F1 to F12 on Mac.

  • F1 : 122
  • F2 : 120
  • F3 : 99
  • F4: 118
  • F5: 96
  • F6: 97
  • F7: 98
  • F8: 100
  • F9: 101
  • F10: 109
  • F11: 103
  • F12: 111

They are not related to ASCII table at all.
Code marked as ‘solution’ or ‘answer’ here doesn’t care of them. They are all converted to a printable characters, ^P.ย So, a table created with the method in the StackOverflow can’t differentiate each of the function keys. So, if you want to differentiate them, customize value saved there using the table above.

It turned out that the database solution, 4D, also had such values for the function keys.
So, it says that the values above is not only specific to my keyboard, Logitechย  K760.

(It’s surprising that 4D is still alive.)

parent selector in Chrome as of today

parent selector in CSS is said to be included in new CSS draft as has() class. A stack overflow comment mentions about it.

Also, on this blog, the author says a reverse selector or parent selector is available with IE and WebKit-based browsers. Chrome was a WebKit-based until Google exited from the WebKit herd. However, in many document, Chrome is mentioned as WebKit-based and there are still lots of WebKit-ness there.
However, as of today, on my Chrome browser on Windows, this parent selector, <, is not available.The version of Chrome browser on my machine is Version 47.0.2526.106 m.

 

 

Way to figure out if a target memory is good to read/write?

Hmmm… IsBad*Ptr() functions are deprecated in Win32 API! Ok.. but what if you need it? Actually there is no reliable way to figure out if a pointer is valid or not. If you suffer such problem, it should be fixed at the caller side or the side where it prepared the pointer.

But.. what if you really need it even though you sufficiently considered that?
What if some external code gives you a bad pointer?

Here is a good blog post, “There is no point improving the implementation of a bad idea.”

There is a simple drop-in replacement and it’s.. reasonable.

Follow

Get every new post delivered to your Inbox.

Join 42 other followers

%d bloggers like this: