יום רביעי, 16 בדצמבר 2015

a talk with Scala REPL

THIS IS A TRUE STORY...
At the request of the survivors,
the names have been changed.
Out of respect for the dead,
the rest has been told exactly
as it occurred


me> 1 to
scala> error: ambiguous reference to overloaded definition,
both method to in class RichInt of type (end: Int, step: Int)scala.collection.immutable.Range.Inclusive
and  method to in class RichInt of type (end: Int)scala.collection.immutable.Range.Inclusive
match expected type ?
       1 to
         ^
me>ah... 1 to 10

...

me> (1 to 10) map _ * 2
scala> error: missing parameter type for expanded function ((x$1) => 1.to(10).map(x$1.$times(2)))
       (1 to 10) map _ * 2
                     ^
me> ah, ok, just a missing curly brackets: (1 to 10) map {_ * 2}

..

me> val a: (Int, Int) = 5,5
scala>:1: error: ';' expected but ',' found.
val a: (Int, Int) = 5,5
                     ^
me> ah, ok, just a missing brackets: val a: (Int, Int) = (5,5)

...

To be continued...

יום שלישי, 10 בנובמבר 2015

Java is not perfect


Java is one of the most popular languages out there for back-end programming. It has many advantages that made it so popular. I am not going to discuss that here.
But Java is old, and keeps compatibility between versions. Some things could have been implemented in a different way, in retrospective.
In this post I want to focus on some syntactic constructs that should be avoided or reconsidered.

  • null - I did not invented it of course, but although it is there it should be avoided. 
Even the inventor said that. What can we use instead? in many cases we are using null when we don't have a value or "answer" to give the client back. Such examples are: return from method, or default behavior in switch statements. 
In many cases it is better to just throw a RuntimeException or IllegalArgumentException to indicate such state. Another way to workaround that is to use Guava's Optional. When returning that from a method, it indicates very clearly that the user of that method should be aware an empty value is possible.
  • Checked exception - First a short reminder: Checked exceptions are exception that when thrown must be declared in the method signature and handled explicitly by the client. 
In Java all exceptions are checked except RuntimeException and Error (and its predecessors). In that case, it is really a matter of taste but here is what I think about using checked exceptions. 
In first glimpse checked exception sounds like a novel idea, similar to the optional above. Implementer can declare in the method signature about errors to allow the client handle them. But it has few major drawbacks that leave them unusable:
    • Checked exceptions are like implementation details that are thrown into the method signature, so for example if your method used files to retrieve a value it will throw IOException. then later the implementer decided to use database, he will throw a JdbcException so the user of the method has to modify the usage because of a change in internal details.
    • Many time - the best place to handle the exception is not directly at the usage of a method but in another, more general place when you can get a valid state to recover from that error. that cause all the methods on the way to get polluted with the exception signature as well. just another details that will make refactor harder.
    • Anyway, a user of a method has to handle runtime exceptions.
    • I saw many cases that it ended up with just throwing the general not-saying-anything Exception. This is like saying that an error might occurred. Ha!
    • Well, no other language used it after Java AFAIK. That is a sign, isn't it?!

  • Language feature such as generics and lambda - In this case I just suggest to be cautious. I have seen far too many cases that a new feature comes to Java, and developers (like myself) just start using it all over the code, make the code unreadable. So when using a new feature, like driving a car, start with a low gear.
  • Un-popular or un-maintained frameworks - Java SDK comes with a lot of goodies, But they do mistakes there also.
Java logging for example, was introduced when log4j was already popular. However, java logging gave a poor api compare to log4j or slf4j. The main advantage of it is you don't have to depend on a third-party library, but you pay for that in convinience. 
A different example is the apache-commons. It was a good library with many features, but it is so ancient and unmaintained that it even doesn't support Java 5 generics well. In most cases I prefer other alternatives such as Google's guava.
That's all for now. LMK what you think.






יום שני, 28 בספטמבר 2015

פחדים וחרדות של ילדים, תפקיד ההורים

פוסט אורח של ד”ר יונתן קושניר
כמה מכם ההורים מכירים את אחד או יותר מהמשפטים הבאים:
“הוא לא נותן לי לישון בלילה”, “אני חייב לשים מזרון בחדר שלה כדי שתישן”, “אני חייב לענות לו על שאלות כל היום אחרת הוא יפחד”, ” מאז שהיא נולדה אנחנו לא יוצאים, לא היינו בחופשה לבד – מרוב חשש היא לא נותנת לנו לצאת”, “היא מחייבת אותי לרחוץ ידיים לפני שאני משחק איתה אחרת היא דואגת שתהיה חולה”, “אנחנו כבר לא בקשר עם יוסי וזהר כי יעל מפחדת ולא מוכנה ללכת לבית שיש בו כלב”, “היא לא נותנת לנו אף זמן פרטי בלילה”, “אנחנו חייבים לענות בשבילו כששואלים אותו שאלה ואם לא יענה הוא ידאג ולא יפסיק לשאול”, ” הילדה שלנו לא מצביעה בכיתה אבל היא כל כך חכמה, היא בטח חושבת שתגיד שטות”, “במסעדה הוא מאוד מתבייש ולא מסוגל לדבר עם המלצר אני חייב להזמין בשבילו ואם הוא מזמין אז זה בקול מאוד חלש, “הילד לא מוכן ללכת לאף הצגה, הוא מפחד מהשחקנים, לכן אף ילד שלנו לא הולך להצגה”.
בנקודה זו עולות כל מיני שאלות לגבי מצבים אלה, למשל:
א.      מה הבעיה/בעיות במצבים אלו?
ב.      האם יש משהו לעשות?
ג.       מי נפגע מזה?
ד.      האם זה לא יעבור מעצמו?
ה.      למה זה ממשיך?
ו.        איפה הבעיה? הבעיה היא בילד? בנו ההורים?
בהמשך המאמר אנסה לענות על שאלות אלו.

יום שני, 17 באוגוסט 2015

What I miss in eclipse when using intellij's idea

After ten years or so working with eclipse I moved to intellij's idea as my primary IDE. The reason for that is that my new team is working with intellij (on Mac!). 
I'v decided to take the long way and use it "as god created it" -- not with eclipse keymap so it will be easy to collaborate with other guys and learn from their experience. In addition, I guess there is some kind of logic for the keymap of shortcuts. Still trying to figure that out.

Definitely the main difference is the keyboard shortcuts. To help me get thru that I created shorty, a small utility that on focus,click the shortcut from eclipse, and the intellij equivalent is displayed.

Another big difference is the (lack of) save button. I am so used to that in eclipse so ctrl+shift+s is like a second nature for me. But that was relatively easy to get used to because I am using webstorm for a while. 
Still, sometime it is annoying. For example when using 'gulp watch', you have to step out of intellij and return in order for the modified files to get noticed for changes. same for save actions and infintest.

I added a list for the rest of the things, please let me know if you find any mistake or I am not using it correctly, so I can learn from it:
  • ctrl + j (find as you type) - I think there is a plugin for that, but didn't try that.
  • duplicating lines and moving them around is much more convenient with eclipse's ctrl + alt + arrow up/down, then leaving the alt to continue the move. intellij has ctrl + d, and I dont like the fact that it is not duplicating full lines on selection.
  • problems view (compilation errors): I am used to see it on the fly so it feels like with intellij I don't see the big picture, rather bump into errors in the build. Speaking of that, intellij is not working so good with compilation errors when trying to run. I tried to configure that but the errors still disturb execution even if its not related to the executed code. I am trying to run unit tests of a class and intellij is shouting about something in completely different area of the code.
  • show the console on new output - why do they don't have that feature?
  • debug java code seems better in eclipse:
    • drop to frame is missing so much.
    • the smart step into is not as convenient as the ctrl+alt+mouse left click shortcut.
    • compiler hot swap is not in the level of eclipse.
  • svn support:
    • I cant make the history view sync with editor file.
    • synchronize view was very convenient.
    • on the other hand I like intellij annotate, change-sets, and shelve support.
  • organize imports - it's just better in eclipse.
Last but not least is the Look&Feel. Eclipse looks so much better in Mac, and on any other platform. Its amazing that a paid product is using swing ui these days. It doesn't looks good and have some weird things that do not feel native to the os.

But there are still a couple of things I like about intellij's idea, maybe the biggest one is the plugins and language support. It is much more mature. You can actually expect a plugin to work. One such an example is subversion support that is "out of the box" unlike subclipse... but there are more. big plus!

And final words about performance & quality. In that case I suffered with both ide's. with large projects they have bottlenecks and doesn't work smooth. I wish it wasn't like that.

יום שישי, 22 במאי 2015

מעט פרגון ל 'עושים היסטוריה'

סיימתי לשמוע את כל הפרקים של עושים היסטוריה שיצאו עד היום. הפודקסט הראשון ששמעתי היה רברסים, מאוד אהבתי ואחרי ששמעתי את רוב הפרקים חבר המליץ לי על עושים הסטוריה של רן לוי.
מהפרק הראשון ששמעתי התלהבתי. רן מעביר את התכנים בצורה מעניינת ובאיכות טובה מאוד. בניגוד לרברסים הפודקאסט אינו טכני, לא דורש ידע מוקדם ויכול לעניין כל אחד. לקח לי יותר מחצי שנה לשמוע את כל הפרקים, את רובם שמעתי בנסיעה לעבודה.
אני משתמש באפליקציית פודקאסט רפובליק באנדרואיד כדי לשמוע את הפרקים.
את רוב הפרקים אהבתי ואני מנסה להיזכר בכמה שאהבתי במיוחד או שפתחו את האופקים בצורה מיוחדת:

פרק 137: הקרב על האטלנטי – צוללות גרמניות במלחמת העולם ה-II
פרק 109: באגים, מזוודות וסוכני FBI- על משבר התכנה
פרק 159: איך לשדוד בנק בשש מילישניות – על מסחר ממוחשב במניות
פרק 154: על אבולוציה וגנטיקה, חלק א' – חווה המיטוכונדריאלית
פרק 149: האיש שקרא לי אידיוט – על ההיסטוריה של קוד פתוח ותנועת התכנה החופשית
פרק 145: מי בכלל צריך אוזן ביונית? על שתל השבלול
פרק 53: איך לשרוד פיצוץ גרעיני.
פרק 40: החיים, היקום וכוס תה- על דאגלאס אדאמס.

את רשימת הפרקים המלאה תוכלו למצוא כאן.
כמה עובדות מעניינות על הפודקאסט:
  • לרן יש תחביב מוזר - מכונות של תנועה מתמדת. כל פרק מסתיים בקטע ממשפחת סימפסון שקשור למכונות אלו: 

  • כל פרק מתחיל בקטע מהסרט "בחזרה לעתיד":


  • תחביב נוסף של רן הוא מדע בדיוני, ויש פרק שלם שמוקדש לבלייד ראנר.
  • כל פרק עשירי עגול מוקדש לסופר מדע בדיוני אחר.
אז תודה לרן על ההשקעה, אתם מוזמנים להאזין.

יום חמישי, 21 במאי 2015

נא לא להפריע!

בזמן האחרון שמתי לב למקרים שבהם הטלפון החכם הופך אותי לפחות חכם. לפעמים מיילים שאני קורא בתזמון גרוע מסיחים את דעתי, אני שוכח לטפל בהם או שפשוט מוחק אותם ושוכח שקראתי. הודעות סמס או ווטסאפ שקופצות דווקא כשאני עסוק במשהו מפריעות לי להתרכז גורמות לי להתעסק במשהו אחר או לא לטפל בהם. אופי העבודה שלי דורש לפעמים ריכוז גבוה וחשיבה, והסחות הדעת האלה יכולות לגרום לירידה בפרודוקטיביות. לפעמים אני מרגיש שזה גורם לי להפרעת קשב וריכוז גם כשאין סיבה ואני פשוט בודק את הטלפון כל הזמן בלי לשים לב.
לאחר אירוע ספציפי שבו 'הואשמתי' שאני לא קורא מיילים :-) החלטתי שצריך לעשות מעשה. או יותר נכון לנהל את האירוע הזה בצורה מודעת ומבוקרת.
אז אני חולק פה את האסטרטגיה שלי לניהול הודעות, ווטסאפים, מיילים וההתראות מהם.
מיילים - גם בבית וגם בעבודה אני דוגל בגישה של תיבת דואר כמעט ריקה, או יותר נכון להשאיר בתיבת הדואר רק דברים שצריכים טיפול. במייל האישי זה די פשוט, אני מעביר לארכיון את כל המיילים שקראתי ולא דורשים טיפול או לאחר שטיפלתי בהם. בדרך כלל יש לי כ - 4 מיילים בתיבה שנשארים להזכיר לי לעשות דברים מתישהו. בנוסף אני משתדל גם מראש לא לקבל מיילים לא רלוונטיים על ידי הסרה מכל רשימת תפוצה ממנה אני מקבל מייל  שאינו מועיל.
המייל של העבודה הוא יותר בעייתי. קודם כל אני מקבל המון מיילים ממערכות אוטומטיות שאין לי דרך מעשית נוחה לצמצם אותם. בשביל זה אני משתמש בכללים של Outloook ושולח אותם לספריות ייעודיות שם אני קורא אותם סלקטיבית מאוד ורק לפעמים. הכלל הכי חשוב שאני משתמש בו כדי למנוע ממיילים שכנראה כן חשובים להיזרק הוא שאם מייל מתחיל ב RE: או FW: אז אני כן שולח אותו לדואר הנכנס ולא מפעיל עליו כללים נוספים. ברוב המקרים אלה באמת מיילים שמישהו כתב ודורשים טיפול. עדיין יש לי מצבים בהם התיבה מתמלאת וצריך לנקות אותה, בעיקר אחרי חזרה מחופשות :-) אני מניח שאם יהיו לי הרבה דברים שדורשים טיפול ממושך אצטרך להשתמש בדגלים או להעביר את המיילים לתיקיה אחרת: "דברים שדורשים טיפול ממושך". בכל מקרה בינתיים אני מסתדר בלי.
לגבי התראות על המיילים - כיביתי את כל ההתראות של המייל הפרטי בטלפון כך שאני ממש צריך להיכנס לאפליקציה כדי לראות מיילים. את המיילים של העבודה אני לא מקבל לטלפון ככה שאין לי התראות עליהם למעט במחשב של העבודה. שמתי לב שלפעמים ההתראה הקופצת במחשב מסיחה את דעתי ואני שוקל לבטל אותה כשאחזור מהחופש. אה, אגב, אני בחופש בגלל זה יש לי זמן לכתוב, אבל על זה אכתוב בהזדמנות אחרת.
ווטסאפ - כל הקבוצות הן מראש חשודות בהפרעות. אני משתדל שכולן יהיו ללא התראה קולית ורובן גם ללא התראה מחוץ לאפליקציה.
סמסים ושיחות - אני מקבל הרבה ספאם גם בסמסים ושיחות בעבר ניסיתי להשתמש בחסימת סמסים אבל לא בהצלחה יותר מידי. כמוצא אחרון אני שוקל להחליף מספר טלפון... אבל כרגע זה עדיין נסבל.
התראות מאפליקציות אחרות בטלפון: פייסבוק, לינקדאין וכו' אני פשוט מכבה את כולן לגמרי.
כמובן שאשמח לשמוע עצות נוספות, ריטלין או כל רעיון אחר.