[Dev Tip] Switching to Java is Self-Destructive!

Over Career forums, I was answering a question by .Net Programmer, he  wanted to switch to Java due to company requirement.  I found some answers supporting the move.  In my view, it is NOT-A-GOOD-IDEA to switch from .Net to Java.  If i were asked on the matter:

My quick answer would be: Do not switch!

Scenario

You are a .Net Programmer with 5+ years of experience.  You love the platform & enjoy your day-to-day programming life.  One day your boss come & says “Buddy… We have a long term Java Project in hand, we require you to learn Java & render the project!”

What you will do?

You will feel regretful in leaving .Net!  A series of thoughts & questions will arise in your mind:

  1. I do not like Java!
  2. Can i learn Java?
  3. What about my hard earned .Net skills?
  4. Is there a risk that I forget .Net?
  5. What will happen to my career?
  6. After 1 year the Industry perceive me as .Net or Java guy?

 

You can always find switching-supporting arguments, preferably from your boss or manager.  Following are some of the tactical arguments which i remember:

  1. Great Programmers never insists on particular language
  2. All languages are converted to machine language for execution, so doesn’t matter .Net or Java!
  3. You won’t forget .Net after 1 year
  4. Java is better than .Net
  5. Having Java in resume will increase your value

Often i see the Information World is more of false/wrong/contextual information.  It takes some real processing to filter out the weed information.  I will answer the above statements at the end of the article.

 

How Career Value is increasing?

Career Growth implies more productivity output for same time-input, more capabilities earned, more quality & more..

We have to see the multiple factors that contribute towards career growth:

  1. Increase by year (more projects >> more knowledge >> more value)
  2. Increase by technology (.net, c#, entity framework, wcf, sql server)
  3. Increase by business acumen (financial, insurance, power sector)
  4. Increase by methodology (cmm, scrum, tdd)
  5. Increase by company (overseas client, mnc exposure)

We are talking about the second point highlighted.

Java is a different animal!

Adding Java to the .Net pack will require you to go through the following preliminary aspects of Java:

  • Learn Java Language
  • Get familiar with IDE
  • Learn Collections
  • Learn GUI aspects
  • Build & Deploy
  • Troubleshoot
  • Learn ORM (Hibernate)
  • Learn J2EE (struts, ejb etc.)

Surely, you end up in a different plane with Java!  You can see that, 1 year working on these aspects won’t add to your .Net experience as it would be a parallel track & no-total-value increase.  So you are wasting your energy.

In the .Net track, value increases if over the years you build on top of knowledge like > windows app > phone app > web app > certifications > .net reflection > componentisation > entity framework > large project implementation > agile > tech lead > team lead > architect > like that..

Same as the case of Java guy switching to .Net.

Work Enjoyment Aspects

Programming is a great Job for the Programmer-Material people.  They enjoy hours spend @ work.  But the enjoyment will be drastically reduced if we are not FAMILIAR with the technology.  Surely a configuration issue can create hectic hours.

While working in Java with amateur training OR no-training, yield your pleasant days to hectic in no-time.  I don’t think these small companies spend enough money on training resources; they will be looking for quick turnaround.

Additionally, working in a less-known technology, create OVER-TIME scenarios.

So working in Java could be PAIN!

Why fresher is paid less?

One thing we should not forget that “When we were freshers, only few companies were ready to hire us”.  Later we gained experience & after 5 years, there are 10 or more companies at the same time to hire us.  This demand/supply fluctuation is made through CAREER VALUE.

As Warren Buffet says “Do not do anything that lose money”, similarly I would say:

“Do not do anything that lose career value!”

Memory Aspects

Learning to Drive a Bike & Learning to use Computer is stored in different memory areas.  But returning to a Bajaj Pulsar bike after you were riding Yamaha Z bike would be a problem – you will face difficulty with gear box, brakes, control etc. (as they work on the same memory area)

Similarly working in Java & returning to .Net after 1 year will surely make difficulties in thinking process, writing code, F5 key to run etc.  These 2 are colliding skills.

I am not a psychiatrist to convey it… But as you are a smart guy, you got what i am trying to say.. Right?

My own experience

I am writing this from my own experience.  Years back i was working in .Net, Delphi, Java, PHP, HTML, VC++, Disassembly, all in one year.  My mind used to get cluttered between Win32 API call, Java SWT, PHP Variable Declaration, and Eclipse & Visual Studio.

I entered this Accident Zone due to my over-helping mentality.    Every quarter my boss will come up with a new client & a far different technology, seeing that nobody accepts the project, I will accept it & stretch myself to learn Java, PHP etc.  Later point of time, I found that company is taking me as a “buffer resource” who can work in all technologies, i became a:

“Jack of All Trades & King of Nothing”

In value aspects my 6 year career, I was paid less than a 2 year Java programmer, that too in the same company!

“So who gained, who lost?”  Clearly company gained what I lost!

So being in the wrong hands, people might exploit your helping attitude!

High Growth Scenario

If we properly take care of our career, empower the right skills, achieve 30% steady & simple growth every year like Sir. Narayana Murthy, then our career will look like this: (GROWTH & LADDER)

But, if you blindly depend on your company, work on all contradictory technologies, switch a lot between technologies, lose your mind, your career will look like this:  (SNAKE & LADDER)

After all, it is you who have to decide the aspects, that Job gives:

  1. Work Enjoyment Part
  2. Monetary Aspects
  3. Financial Freedom

My Answers

As per the promise, I am trying to put my answers against the tactical “supporting-thoughts” by deceivers:

  1. Great Programmers never insists on particular languageYes.  You are right.  But i say if they insisted on particular language, they would have been EVEN-GREATER!  For example all the Tech Authors, Tech Leads, MVPs are a result of focusing on particular technology or language.  So focus is value, focus is growth!
  2. All languages are converted to machine language for execution, so doesn’t matter .Net or Java!  I don’t know what to say for this.  I can counter it saying “All human beings are ultimately Animals with advanced brain!  Do we treat animal equal to human?” NO.. Similarly there is difference in .Net & Java.  The skill experience determines the productivity factor of .Net, so how quick the machine language is created depends on skill level, so .Net matters!
  3. You won’t forget .Net after 1 yearWe won’t forget .Net after 1 year, but the 1 year can definitely corrode the skill efficiency for sure, we won’t be sharp enough as we were 1 year before.  It requires thorough regression to get back to old foam!
  4. Java is better than .NetConsidering the latest .Net Platform, C#, Associated Technologies, I would say .Net is way ahead than Java.. Challenge >> Read this
  5. Having Java in resume will increase your valueIt can only increase value if the company is looking for hybrid-programmers, such opportunities are less in the programmer level & more in the solution architect level.  So in general case, it will not increase the value & you will get confusing calls from Java Hunters, if the keyword  Java is in your resume.

Boss’s thought

From the management side, they won’t like these points.  They prefer resource-reuse as switching technology helps with:

  1. Reduced cost as no-new java programmer is hired
  2. Improved return on existing resource as idle time of .Net programmer is avoided

In my management experience, we were happy to reuse resources, but i would be honest to tell upfront that it will reduce their career value; I do not like people coming back to me & saying i cheated them.

Boss will ask you to see things in his stand point; Programmer can ask-back to see things from the programmer stand point! 

In most cases, the switching of technology marks a permanent move as the company is not interested to get back the programmer to previous state, but in the case of idle programmer, the company would be motivated to get a .Net project to reduce idle time.

Remember one thing; some companies have tricky managers who make sure the employees won’t grow in value, so that they can use a 10 year programmer at the cost of 3 year guy!  Such leaders are temporary solution seekers, never stick to them as they are lacking humanity values.

 

Another School of Thought

In the film industry, I have observed some Actors will play role of Hero & Villain within the same year, but they won’t reach the top layer as their IMAGE is struck between multiple characters.  They do the switching due to necessity OR they wanted to enjoy different styles, sometimes being Hero for multiple movies make their life boring.  In this case switching is yielding some benefits of work-enjoyment, but definitely they are losing value.

The IMAGE of an actor determines his success leverage.  This is the reason SRK is high value in Bollywood.  If he plays the role of Arrogant Villain for 2-3 films, he is gone out of value!

 

Concluding, Switching tracks is Self-Destructive!

Summary

I honestly believe that, I have produced the solid facts against Switching-to-Java.  Switching career-path impacts future:

  1. Career Value
  2. Money Value
  3. Work Enjoyment Factor

I would say; I made the mistake years back & I would be happier if my bad-experience helped another person from repeating the same!  Btb.. i support the thought we should keep an overview of all technologies like java, iphone, android etc, but not at the cost of our career!

So, if .Net Career is a Country, switching to Java is like ATTACK on the Borders!  Apne watan ki raksha karo logom 🙂

I am open for thoughts from other programmer savvy’s.. (not managers though) 🙂

[Dev Tip] Another time usage on .NET

Noda Time is an alternative date and time API for .NET. It helps you to think about your data more clearly, and express operations on that data more precisely.

And basic using:

I was planning on converting these times to UTC/Noda Instants to prevent the need to store all the time zone info with each date in the database.

That’s fine if you don’t need to know the original time zone later on. (e.g. if the user changes time zone, but still wants something recurring in the original time zone).

Anyway, I would separate this out into three steps:

  • Parsing into a LocalDateTime
  • Converting that into a ZonedDateTime
  • Converting that into an Instant

Something like:

// TODO: Are you sure it *will* be in the invariant culture? No funky date
// separators?
// Note that if all users have the same pattern, you can make this a private
// static readonly field somewhere
var pattern = LocalDateTimePattern.CreateWithInvariantCulture("yyyy/MM/dd HH:mm");

var parseResult = pattern.Parse(userSubmittedDateTimeString);
if (!parseResult.Success)
{
    // throw an exception or whatever you want to do
}

var localDateTime = parseResult.Value;

var timeZone = DateTimeZoneProviders.Tzdb[userTimeZone];

// TODO: Consider how you want to handle ambiguous or "skipped" local date/time
// values. For example, you might want InZoneStrictly, or provide your own custom
// handler to InZone.
var zonedDateTime = localDateTime.InZoneLeniently(timeZone);

var instant = zonedDateTime.ToInstant();

[Discovery] Đi tìm giới hạn sức chịu đựng của cơ thể con người

Chúng ta đã từng được nghe kể về những câu chuyện sống sót thần kỳ của những người lênh đênh trên biển hàng tháng trời, hay bị rơi từ tầng 10 của một tòa nhà, thậm chí bị một viên đạn bắn xuyên qua não. Những câu chuyện này cho thấy sức chịu đựng rất lớn của cơ thể con người. Tuy nhiên chúng ta vẫn có giới hạn của chính mình.

“Quy tắc 3” là một trong số những lý thuyết nổi tiếng về giới hạn sức chịu đựng của cơ thể con người, đó là chúng ta không thể nhịn thở quá 3 phút, không thể không uống nước quá 3 ngày và không thể nhịn ăn quá 3 tuần. Bên cạnh đó có nhiều giới hạn khác của con người mà chúng ta chưa thể khám phá hết, như bạn có thể leo lên độ cao giới hạn nào trước khi chết vì ngạt thở, hay có thể lặn xuống độ sâu bao nhiêu trước khi chết vì áp lực nước, hay chúng ta có thể di chuyển với tốc độ tối đa bao nhiêu trước khi bị xé nát thành nhiều phần.

Chúng ta có thể không ngủ bao nhiêu ngày?

Trước đây, đã có những báo cáo ghi nhận có vụ phi công máy bay trở nên mê sảng sau 3-4 ngày không ngủ và khiến chiếc máy bay chiến đấu lao thẳng vào một vách núi, hay tác động của việc thiếu ngủ tương tự như say rượu đối với các tài xế xe tải. Điều này cho thấy tác hại rất lớn từ việc thiếu ngủ. Tuy nhiên một cậu bé 17 tuổi tên là Randy Gardner đã từng lập kỷ lục Guiness bằng cách không ngủ trong 11 ngày.

Đi tìm giới hạn sức chịu đựng của cơ thể con người

Mặc dù vậy, đã từng có vụ một người đàn ông Trung Quốc bị chết sau 11 ngày không ngủ vì xem tất cả các trận đấu của cúp Euro. Nhưng ông cũng uống rượu và hút thuốc suốt 11 ngày đó, khiến việc xác định nguyên nhân cái chết có phải do thiếu ngủ hay không gặp nhiều khó khăn. Vì lý do đạo đức mà các nhà khoa học cũng không thể tiến hành các thí nghiệm tương tự trong phòng thí nghiệm.

Vì thế, các nhà khoa học tại đại học Chicago đã tiến hành một thí nghiệm trên loài chuột. Họ làm cho chúng không thể ngủ và ghi lại những thay đổi trong cơ thể cũng như sóng não. Kết quả là tất cả những con chuột thử nghiệm đều không thể sống quá 20 ngày, cơ thể chúng xảy ra hiện tượng đốt cháy calo quá mức trong khi không hề vận động gì và vẫn được ăn uống bình thường. Các nhà khoa học cũng dự đoán cơ thể con người không thể chịu đựng quá 15 ngày mà không ngủ, mặc dù vẫn ăn uống bình thường và không hoạt động nặng.

Gia tốc tối đa có thể chịu đựng?

Kỷ lục tốc độ bay hiện nay là 11.270 km/h của NASA X-43A, chứng tỏ cơ thể chúng ta có thể chịu đựng được vận tốc rất lớn. Tuy nhiên gia tốc lại là sự khác biệt lớn, sự thay đổi vận tốc lớn trong khoảng thời gian ngắn ngủi có thể gây ra một lực khủng khiếp. Nó có thể ép nát cơ thể của chúng ta và làm tổn thương các cơ quan nội tạng bên trong.

Đi tìm giới hạn sức chịu đựng của cơ thể con người

NASA và các nhà khoa học quân sự đã phải nghiên cứu rất kỹ lưỡng vấn đề này, nhằm thiết kế tàu vũ trụ và máy bay chiến đấu, đảm bảo an toàn cho các phi công trước sức ép rất lớn khi tăng tốc với gia tốc lớn. Theo các nghiên cứu, cơ thể con người có thể chịu được gia tốc khoảng 4-8 G theo chiều dọc từ đầu đến chân, trước khi máu của chúng ta bị dồn lại hết về một phía (1G chính là trọng lực, lực hấp dẫn của Trái đất khoảng 9,8m/s2).

Còn theo chiều ngang, cơ thể của chúng ta có thể chịu đựng được khoảng 14G trước khi các cơ quan bên trong bị tổn hại. Trong khi đó cơ thể con người có thể chịu đựng được gia tốc lớn nhất là theo chiều từ trước ra sau cơ thể, vì có lồng ngực bảo vệ các cơ quan bên trong. Một thí nghiệm quân sự năm 1950 với chiếc xe trượt tuyết gắn động cơ tên lửa cho thấy con người có thể chịu gia tốc lên tới 45G theo hướng này. Có nghĩa là chiếc xe tăng tốc từ 0 – 1000 km/h chỉ trong vòng 1s. Các nhà khoa học ước tính cơ thể chúng ta sẽ không thể chịu quá 50G, lúc đó các cơ quan bên trong sẽ bị nghiền nát bởi sức ép rất lớn.

Sức chịu đựng nhiệt độ của cơ thể

Theo một báo cáo năm 1958 của NASA, con người có thể sống trong điều kiện nhiệt độ môi trường dao động từ 4 – 35 độ C. Nhiệt độ tối đa có thể đẩy lên nếu độ ẩm không khí thấp, vì lượng nước trong không khí thấp hơn thì cơ thể sẽ dễ dàng đổ mồ hôi hơn và giúp làm giảm nhiệt độ của cơ thể.

Đi tìm giới hạn sức chịu đựng của cơ thể con người

Cơ thể chúng ta có thân nhiệt ổn định ở mức 37 độ C, tuy nhiên nếu nhiệt độ môi trường làm giảm thân nhiệt, sẽ gây ra những ảnh hưởng rất rõ rệt. Nếu nhiệt độ cơ thể giảm xuống 35 độ C, chân tay bạn sẽ run lên và rất khó cử động. Tại 32 độ C, hầu hết mọi người sẽ bất tỉnh, cơ thể sẽ từ bỏ cố gắng để duy trì thân nhiệt. Hơi thở giảm xuống và rối loạn nhịp tim khi nhiệt độ còn 28 độ C. Và khi thân nhiệt chỉ còn 20 độ C, tim sẽ ngừng đập. Mặc dù vậy, đã từng có trường hợp một cô gái đi bộ trong thời tiết -20độ C và thân nhiệt chỉ còn 16 độ C nhưng vẫn được cứu sống.

Có vẻ chúng ta chịu lạnh tốt hơn là chịu nóng. Nhiệt độ cao nhất của cơ thể mà có thể duy trì sự sống là 42 độ C, vì ở nhiệt độ này các protein cần thiết của cơ thể bắt đầu bị phân hủy. So với nhiệt độ bên ngoài, ngay cả lính cứu hỏa với trang bị đầy đủ cũng chỉ có thể chịu được mức nhiệt độ môi trường lên tới 93 độ C.

Leo núi và lặn dưới đáy đại dương

Càng lên cao áp suất khí quyển càng giảm và không khí càng loãng, làm cho lượng oxy cũng giảm sút. Chúng ta sẽ chết khi nồng độ oxy trong không khí giảm xuống dưới 11%. Theo tính toán của các nhà khoa học, chúng ta sẽ không thể thở mà không có bình dưỡng khí trên độ cao khoảng 7,900m.

Trong khi đó, nếu lặn xuống dưới đáy biển mà không có những thiết bị đặc biệt, chúng ta sẽ bị thiếu oxy và chịu áp lực rất lớn của nước. Thông thường một người có thể lặn sâu xuống khoảng 18m. Nhưng kỷ lục thế giới ghi lại độ sâu lớn nhất mà con người có thể lặn xuống là 85m.

Và những giới hạn khác của cơ thể

Một người bình thường có từ 3,8 đến 5,6 lít máu. Bạn có thể mất khoảng 15% lượng máu trong cơ thể mà không có bất kỳ ảnh hưởng nào. Tuy nhiên nếu bị mất một lượng máu lớn hơn, bạn sẽ cảm thấy chóng mặt, tim đập nhanh. Khi bị mất khoảng 40% máu, huyết áp lúc này quá thấp để đẩy máu đi và tim bắt đầu loạn nhịp. Nếu vượt quá mức 50%, trái tim của bạn sẽ không thể chịu đựng được và sẽ dẫn tới cái chết.

Hơn 60% cơ thể chúng ta là nước, do đó nước rất quan trọng. Tuy nhiên uống quá nhiều nước không phải là điều tốt, mà thậm chí có thể khiến chúng ta mất mạng. Theo các bác sĩ, 10L nước là lượng nước tối đa bạn có thể uống trong vòng 1 giờ mà không làm loãng các chất điện giải trong cơ thể khiến các cơ co giật và có thể tử vong.

Độ lớn của âm thanh được đo bằng đơn vị decibel. Khoảng 30dB là độ lớn âm thanh tại các làng quê yên tĩnh, trong khi đó 120dB là độ lớn mà bạn có thể nghe thấy tại các liveshow rock. Âm thanh lớn nhất mà chúng ta có thể nghe có độ lớn khoảng 160dB, nếu âm thanh có độ lớn vượt quá ngưỡng này có thể khiến màng nhĩ bị rách. Khi âm thanh có độ lớn 200dB, các sóng âm thanh có áp lực lớn thậm chí có thể làm vỡ phổi, đẩy không khí vào các mạch màu gây ra nghẽn các mạch máu dẫn tới tử vong.

Đi tìm giới hạn sức chịu đựng của cơ thể con người

Chết vì điện giật là một nguyên nhân rất phổ biến. Nguyên nhân gây ra cái chết không phải là mức điện áp lớn, mà là cường độ dòng điện (ampe). Một dòng điện khoảng 1mA có thể gây ra một chút cảm giác tê tê, trong khi đó một dòng điện 200mA là đã đủ để lấy đi mạng sống của chúng ta. Điện trở của da người thay đổi từ 1.000 Ôm (da ướt) đến 100.000 Ôm (da khô), do đó mà mức điện áp tương ứng có thể gây chết người là 200V (da ướt) và 20.000V (da khô). Trên thực tế, chỉ 10% những vụ sét đánh trúng gây ra tử vong.

Tham khảo: livescience, dailymail, theadrenalist

[Dev Tip] Stress test with Apache JMeter

Performance is a critical aspect of most applications. Everything may be pretty, really well developed, intuitive and all, but if the performance is not up to par the user experience is going to suck.

Unfortunately most of these performance problems only show themselves after some time in production, making them much more cumbersome to solve and handle.

In this post I’m going to talk about something that should, IMHO, be integrated in the development lifecyclebefore the application goes live: Load-tests.


I typically talk separately about performance-testing and load-testing. For me performance testing is something you would do with a profiler like dotTrace or ANTS, where you run your application in the context of a user, trigger some functionalities, take some snapshots and then analyze the results. Typically with a profiler you understand the code where most time is spent on.

Load-testing is a different beast. You’re testing the ability of the application to, with enough load, be able to handle requests at an acceptable rate.

With a good load testing strategy, and taking into account the target hardware, you’ll be able to estimate the capacity of your solution in terms of simultaneous users / requests. Also, and very importantly, you may understand if your solution is able to scale well or not. This is of extreme importance because nowadays it’s cheaper (and less riskier) to buy a new server than to pay your developers to refactor/optimize the solution.

With that in mind, in this series of posts I’m going to show some tools that I’ve used for load testing in the context of ASP.NET MVC, starting with a really basic one called Apache Workbench and then evolving into a much more powerful tool called jMeter.

Apache Worbench

For simpler scenarios nothing beats Apache Workbench. It’s a single executable that is able to trigger simultaneous HTTP operations on a specific URL, displaying some really simple metrics.

It’s included with Apache, but it’s not very practical to install Apache just to get this small executable. You can follow the tips here to get the file.

Now, let’s create our sample website. Nothing here will be ASP.NET MVC specific, so use anything that rocks your boat. I’m going to use the empty ASP.NET MVC template and create a really simple Home controller with an index action that returns a view.

After extracting “ab.exe” lets run it at a command prompt. It’s usage is:

Usage: ab [options] [http://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make
    -t timelimit    Seconds to max. wait for responses
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header for POSTing, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234. (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    -P attribute    Add Basic Proxy Authentication, the attributes
                    are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -r              Don't exit on socket receive errors.
    -h              Display usage information (this message)

Let’s start by running it as:

ab -n10 -c1 http://localhost:5454/Home/Index

We’re basically issuing 10 sequential requests. The results:

Concurrency Level:      1
Time taken for tests:   0.041 seconds
Complete requests:      10
Failed requests:        0
Write errors:           0
Total transferred:      4390 bytes
HTML transferred:       260 bytes
Requests per second:    243.89 [#/sec] (mean)
Time per request:       4.100 [ms] (mean)
Time per request:       4.100 [ms] (mean, across all concurrent requests)
Transfer rate:          104.56 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.5      0       1
Processing:     1    4   2.4      3       9
Waiting:        1    3   2.4      3       9
Total:          1    4   2.7      3      10

Percentage of the requests served within a certain time (ms)
  50%      3
  66%      4
  75%      5
  80%      6
  90%     10
  95%     10
  98%     10
  99%     10
 100%     10 (longest request)

Almost every metric here is useful and should be easy enough to understand. Typically the main metrics that I look for are:

  • Requests per second
  • The mean time per request
  • 95% interval -> meaning in this case that 95% of the times the request time is less or equal to 10 ms (this metric is commonly used in SLA specifications).
Let’s make things more interesting. I’m going to change my action to be:
public ActionResult Index()
{
    Thread.Sleep(500);
    return View();
}

Now, running the same command again:

ab -n10 -c1 http://localhost:5454/Home/Index

Results:

Requests per second: 1.99
Time per request: 503.29 (mean)
95%: 504 ms

Makes perfect sense. We’re issuing sequential requests and every one takes half a second to execute.

Now, if we add parallelism to the equation:

ab -n10 -c10 http://localhost:5454/Home/Index

Results:

Requests per second: 9.89
Time per request: 1011.058 (mean)
95%: 1010 ms

The performance starts to deteriorate. Although its processing almost 10 per second the mean time per request has surpassed 1 second.

And we can even make it worse:

ab -n100 -c100 http://localhost:5454/Home/Index

Results:

Requests per second: 16.40
Time per request: 6099.349 (mean)
95%: 6069 ms

Almost 6 seconds por
Now, suppose that our SLA stated that we needed to handle 95% of the requests in less than 1 second. Our capacity would be around 10 simultaneous requests.

It’s not the focus of this post to try and optimize this code, but just for the fun of it, let’s try to understand what’s happening here.

While issuing the Thread.Sleep, the thread is literally blocked half-a-second while waiting to resume execution. Obviously your own code would not have a Thread.Sleep (I hope), but the same principle applies while waiting for a synchronous query to the database, or a synchronous filesystem operation, etc.

Let’s make our operation asynchronous to see if it does improve the capacity of our application. Fun, fun, fun, let’s use the new async/await goodness to create an asynchronous action. The code becomes just:

public async Task<ViewResult> Index()
{
    await Task.Delay(500);
    return View();
}

Freeking awesome. Let’s test it with the same parameters as before:

ab -n10 -c1 http://localhost:5454/Home/Index

Results:

Requests per second: 1.96
Time per request: 510.129 (mean)
95%: 517 ms
ab -n10 -c10 http://localhost:5454/Home/Index

Results:

Requests per second: 19.16
Time per request: 522.030 (mean)
95%: 521 ms
ab -n100 -c100 http://localhost:5454/Home/Index

Results:

Requests per second: 162.07
Time per request: 617.035 (mean)
95%: 602 ms
Mean Time per Request (ms)

So, as you can see, load-testing is very important. In my next post I’m going to show a much more powerful tool called jMeter. What I’ve shown here is just the tip of the iceberg.

 

Although Apache Workbench provides some simple and useful metrics it’s a little bit limited. In this post I’m going to talk about a much more powerful tool for load-testing: JMeter (also from the Apache Foundation).

I’ll start by replicating the previous experiment that I did with Apache Worbench but using JMeter, and gradually adding more complexity to it.


Let’s get started:

  • Extract the archive somewhere on your disk and run the <folder>/bin/jmeter.bat file (Java required)
JMeter is not a particularly intuitive application. When starting you get this home screen.
You have a Test Plan node and a workbench. The workbench works like a Sandbox. Nothing you place there is saved implicitly with your tests. According to the JMeter manual the workbench is:
 
“(..) a place to temporarily store test elements while not in use, for copy/paste purposes, or any other purpose you desire”
 
Yeah, a little bit weird. Anyway, the Test Plan is where you place the test itself. If you right-click it you might be a little overwhelmed with all the available options, but the JMeter page does a really nice job in explaining each of the available options. You can check the manual at http://jmeter.apache.org/usermanual/.
Step 1: Simple HTTP Get Requests
 
Now, the typical basic JMeter test has a Thread, a Sampler and a Listener. In the context of our first test this will mean:
  • Thread: configuration of number of users and number of executions. Similar to the parameters we tweaked in Apache Worbench
  • Sampler: the HTTP Request configuration
  • Listener: Handles the requests and results and produces result metrics.
So, without further ado, let’s create all these items:

Thread:

  • Test Plan > Add > Threads (Users) > Thread Group

 

  •  Let’s create 10 users, where each launches 10 simultaneous requests.

So, we’ll have a total of 100 requests. The ramp-up period is very useful in more realistic testing scenarios and represents the interval between each thread (user) submitting requests. In this case, as we’re trying to mimic the behavior from our Apache Worbench test from my previous post, I’ve set it to 0 (zero).

Sampler:

  • Thread Group > Add > Sampler > HTTP Request
  • Fill the request information. Obviously the server name, port number and path may vary.

Listener:

  • Thread Group > Add > Listener > Summary Report
  • Launch the Test
  • The Summary Reports shows basic information regarding our test.
As you can see 100 samples were produced with an average time of 516 ms. There are LOTS of other result listeners, allowing you to show information about each request, export to CSV, graphs, etc.

Step 2: HTTP Get Requests with dynamic parameter and measuring success


We’ll pick the previous example and send a dynamic sequential parameter, created by a JMeter counter. Then, the server will give a success or failure error message depending if the number is odd of even. So, we’ll add to the existing example:

  • Counter
  • Tree Listener
  • Response Assertion

First of all we’ll have to change the asp.net mvc project.

The action implementation will be:

public async Task<ViewResult> Index(int id)
{
    await Task.Delay(500);

    this.ViewBag.Id = id;
    this.ViewBag.Success = id % 2 == 0;

    return View();
}

And the view:

@{
    ViewBag.Title = "Index";
}

<p>@(ViewBag.Success ? "Success" : "Error")</p>

<p>Item ID:@ViewBag.Id</p>

So, opening the page should show a different result if the parameter is odd or even:

Regarding JMeter:

Counter

  • Thread Group > Add > Config Element > Counter
  •  Fill the counter information. Basically it’ll increment its value by one on each iteration and store the result on a variable called COUNTER.
  • Let’s change our HTTP request to use this counter value. To use variables in JMeter the notation ${VARIABLE} is used. Thus, in our case, our HTTP request url should become: /Home/Index/${COUNTER}
Tree Listener
 
This is my favorite result listener during development as it shows each request, including the full response.
  • Thread Group > Add > Listener > View Results Tree
  • Rearrange the items using Drag&Drop so that they become like this:
  • Launch the Test
Now, besides having the Summary Report as before, we can also see each request in the “View Results Tree” item. There we can confirm that each request is being sent with a different ID (from the counter) and that the response has a different message when using odd or even IDs.
Response Assertion
 
Now, sometimes we need to measure the success of a request according to the response we got. In this case, we’ll consider a success if the response has the text “Success”.
  • Thread Group > Add > Assertions > Response Assertion
  • Configure the assertion
  • Now run the test. Half of the requests will be considered errors (the ones with odd IDs)
This response assertion thing is more important than you may consider at first glance. Follow my advice: always have a Response Assertion in place to make sure that your results are not tampered.
Now, this post is starting to be a little big so I’ll wrap this up on a third post where I’m going to talk about some additional things:
  • Using Variables and other misc stuff
  • Submitting HTTP POST (also, using the HTTP Proxy)
  • Handling authentication
  • Handling the ASP.NET MVC Anti-Request forgery token
  • Loading data from a CSV file

As promised, in this post I’m going to explain some more JMeter stuff. So, I’ll show how to:

  • Submit information (HTTP POST)
  • Handle authentication
    • Particularly in the ASP.NET MVC context
  • Read information from a page and store it in a variable
    • Particularly to read the ASP.NET MVC anti-forgery token
  • Vary the posted data by reading it from a CSV file
Also, I’ll include some extra elements to make the test more maintainable and professional.
So, again, lots of ground to cover so lets get started.

First, we need to create the application that will be tested. It’ll be pretty simple: a login screen and a form with a bunch of fields. After submitting it should show a success or error message according to the validation.

So, this is the login screen:

After supplying the correct credentials (meaning, password = “password”) a page is opened with 2 fields ready to submit feedback.

The page has validation set up

And after filling the two fields correctly a message appears and the form fields are cleared so that new feedback may be supplied.

That’s it. Now, there’s some small details to take into consideration.

  • The web page has Forms Authentication. Pretty standard stuff: if the credentials are valid then create the authentication cookie.
  • I’m using an ASP.NET MVC mechanism to defend against Cross-Site Request Forgery by supplying a token in the HTML Form that must be sent on the POST. This is done by using the ActionFilter [ValidateAntiForgeryToken] on the action and a @Html.AntiForgeryToken on the view. So, if a POST request does not include the anti-forgery token the server will reject the request and throw an exception.

Let’s create a pseudo-representation for our test-plan:

For each User
 |
 +--- Login
 +--- Repeat n times
         |
         +--- Submit Feedback
         +--- Wait a couple of seconds before submitting again

This will roughly translate to:

Now, as this is the second post on JMeter I’m going to jump some hoops and show the final test plan and then explain each of the elements.

This might seem a little scary but most of the elements should be really easy to grasp. I’m going to show the configuration for each one:

Test Configuration
 
It’s really useful to have all the configuration in one spot, typically at the start of the test. This way we can tweak stuff more easily.


HTTP Request Defaults
 
Instead of repeating the server and port on each request we can define defaults for those values. This is really a time-saver, particularly when switching environments.
 
HTTP Cookie Manager
 
The cookie manager is the only thing required to handle forms authentication. It makes sure that the authentication cookie is there, making your requests authorized after the login.
 
 
For Each User
 
Normal thread, but using variables instead of hardcoded numbers. The Loop Count is 1 because we have a Loop Controller inside.
 
 
Login
 
The login is a simple post to a specific action on our website. The username is always supplied as “DummyUser” with a “password” password.
Notice that the server name and port number are empty, as we’re using the HTTP request defaults.
 
 
Open Feedback Page
 
Just opening the feedback page before submitting. This is required because of the next action.
 
Regular Expression Extractor
 
The Request verification token is a hidden value in the form. Something like:
<input name="__RequestVerificationToken" type="hidden" value="........"/>
We have to load that field into a JMeter variable. Thus we use a Regular Expression Extractor, passing the following regular expression:

name=”__RequestVerificationToken” type=”hidden” value=”([A-Za-z0-9+=/\-\_]+?)”

 
Repeat
 
Pretty self-explanatory. Repeat n times for each user (thread).
 
Load data from file
 
It’s a good idea to have diversity on your tests. Thus, instead of having hardcoded values, we can read values from a CSV file and assign them to variables. These may then be used normally in JMeter.
For example, I’ve created a csv file, named “Feedback.csv” with this content:
Nice Site;I really enjoyed that movie
Pretty good;I liked it, but there's some stuff that I didn't really getAwful;This is the worst piece of **** I've ever seen
Interesting;Nice stuff
(...)
much more lines. Should be enough to fulfill the number of users * number of requests.
One thing to note is the Sharing mode. With “All threads” it means that each request for each user will choose a new value from the csv file.

Submit Feedback
 
This is where the feedback itself is submitted. Notice that all the values use variables and that the Request Verification Token is also sent.
 
Check Result
 
Just checking if the response shows a success message or not.

Wait Before Next Request
 
If we’re simulating real users, we want to wait a little bit before issuing another request. I like the Gaussian Random Timer a lot because the value is a “controlled random” as it follows a normal (Gaussian) distribution on the test-plan as a whole.

The scary part is that JMeter provides much more stuff than what I’ve shown here. Anyway, I’ll wrap up things for now. If you’ve got any doubt/suggestion place a comment.

[Discovery] Con người trong tương lai sẽ được cấy ghép trí tuệ bằng các dung dịch có chứa dữ liệu?

cay_ghep_nao.

Bạn có tin rằng trong tương lai, toàn bộ dữ liệu kỹ thuật số sẽ được lưu trữ dưới dạng dung dịch và có thể cấy vào trong não để gia tăng hiểu biết của bạn? Điều đó có thể sẽ trở thành hiện thực nhờ vào một nghiên cứu dẫn đầu bởi kỹ sư hóa chất Sharon Glotzer tại Đại học Michigan nhằm phát triển phương pháp lưu trữ thông tin bằng các cụm vi hạt trong dung dịch. Theo đó, các cụm vi hạt chứa trong chất lỏng sẽ thay thế cho transitor truyền thống nhằm thực hiện các chức năng cơ bản nhất của điện toán. Và nếu kết hợp nhiều cụm hạt với nhau, chúng ta có thể lưu trữ được khối lượng dữ liệu khổng lồ nhằm phục vụ cho nhiều hoạt động của con người trong tương lai.

Lấy cảm hứng từ cấu trúc của khối Rubik với các khối lập phương đầy màu sắc có thể xoay quanh vị trí trung tâm và tạo thành nhiều hình thái khác nhau, nhóm nghiên cứu đã có ý tưởng thay các khối lập phương bằng những vi hạt đính xung quanh một hạt trung tâm, mỗi cách sắp xếp của các hạt nhỏ sẽ tương ứng cho lượng thông tin nào đó cần biểu thị. Một thí dụ đơn giản, khi đặt 1 cụm hạt vào trong chất lỏng, cấu trúc của chúng sẽ chuyển đổi qua lại giữa 2 hình thái khác nhau và tương ứng với hoạt động đóng mở của transitor (trị số 1 hoặc 0). Đây chính là hình thái cơ bản nhất của thông số được sử dụng trong công nghệ điện toán từ trước đến nay.

Trong báo cáo chi tiết do nhóm nghiên cứu công bố, kỹ sư Glotzer cho biết: “Chúng tôi muốn chứng minh việc dùng vật chất nano để lưu trữ thông tin thay cho các transitor là điều hoàn toàn có thể thực hiện được. Nếu chúng ta có thể liệt kê toàn bộ những trạng thái của cụm hạt và tìm được cách chuyển đổi qua lại giữa các trạng thái thì sẽ hoàn toàn có thể dùng nó để mã hóa thông tin. Càng có nhiều hạt thì càng có nhiều trạng thái và lượng thông tin lưu trữ cũng theo đó mà tăng lên.” Theo ước tính của nhóm nghiên cứu, 1 muỗng nước chứa các hạt nano có thể lưu trữ được khối dữ liệu có kích thước lên tới 1TB.

Không chỉ dừng lại ở việc phát hiện ra một hình thức điện toán mới mà nhóm nghiên cứu còn mong muốn có thể áp dụng phương pháp trên nhằm tạo ra những con chip sinh học nhằm cấy ghép cho con người. Một ứng dụng cụ thể là tạo ra cảm biến cấy vào máu nhằm theo dõi nồng độ glucose và đưa ra cảnh báo thích hợp cho người bệnh. Trong một ứng dụng khác, kỹ thuật điện toán trên có thể được sử dụng làm bao bì đóng gói có thể đổi màu nhằm hiển thị cho tình trạng của loại thực phẩm chứa bên trong.

Một ý tưởng khác táo bạo hơn là cấy ghép dung dịch chứa cụm nano vào trong não người nhằm hỗ trợ tính toán, lưu trữ mà không cần phải dùng đến máy tính. Đồng thời cho phép mỗi cá nhân có thể tìm hiểu và hấp thụ được một lượng thông tin vô cùng lớn trong thời gian ngắn hơn nhiều lần so với cách học tập thông thường.

Dĩ nhiên, tất cả các ứng dụng trên đều là suy đoán đầy hứa hẹn của nhóm tác giả nghiên cứu. Hiện tại, công việc nghiên cứu chỉ còn dừng lại ở mức độ phát hiện hết sức sơ khai và vẫn còn rất nhiều vấn đề mà các nhà nghiên cứu còn phải giải quyết trong tương lai. Dù vậy, rõ ràng đây là một phát hiện đầy hứa hẹn cho phép chúng ta mơ về một thế giới với những con người siêu thông minh, có thể học những kiến thức mới bằng cách copy và dán vào trong não!

[Infographic] Lịch sử phát triển của tiền tệ

header.

Có thể nói tiền là một trong những phát minh quan trọng đối với sự phát triển của loài người. Nó là vật ngang giá chung, thước đo giá trị, công cụ tích trữ, … giúp việc giao thương của con người dễ dàng hơn rất nhiều.

Đồng tiền đã phát triển qua nhiều giai đoạn và ngày càng thuận tiện hơn cho người dùng: hàng đổi hàng, tiền vàng, tiền kim loại, tiền giấy, tiền điện tử,… Đồng tiền khác nhau ở mỗi quốc gia, vùng lãnh thổ. Cho đến năm 2012, đã có 167 loại tiền tệ khác nhau lưu hành trên thế giới.

Infographic dưới đây tổng hợp các mốc phát triển của đồng tiền trên thế giới.

Lich-su-phat-trien-cua-tien-te.

Nguồn: cdn.history.com

[Dev Tip] What Great .NET Developers Ought To Know (More .NET Interview Questions)

A while back, I posted a list of ASP.NET Interview Questions. Conventional wisdom was split, with about half the folks saying I was nuts and that it was a list of trivia. The others said basically “Ya, those are good. I’d probably have to look a few up.” To me, that’s the right response.

Certainly I wasn’t trying to boil all of .NET Software Development down to a few simple “trivia” questions. However, I WAS trying to get folks thinking. I believe that really good ASP.NET (and for that matter, WinForms) is a little [read: lot] more than just draging a control onto a designer and hoping for the best. A good race driver knows his car – what it can do and what it can’t.

So, here’s another list…a greatly expanded list, for your consumption (with attribution). I wrote this on a plane last week on the way from Boise to Portland. I tried to take into consideration the concerns that my lists contain unreasonable trivia. I tried to make a list that was organized by section. If you’ve never down ASP.NET, you obviously won’t know all the ASP.NET section. If you’re an indenpendant consultant, you may never come upon some of these concepts. However, ever question here has come up more than once in the last 4 years of my time at Corillian. So, knowing groking these questions may not make you a good or bad developer, but it WILL save you time when problems arise.

What Great .NET Developers Ought To Know

Everyone who writes code

  • Describe the difference between a Thread and a Process?
  • What is a Windows Service and how does its lifecycle differ from a “standard” EXE?
  • What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?
  • What is the difference between an EXE and a DLL?
  • What is strong-typing versus weak-typing? Which is preferred? Why?
  • Corillian’s product is a “Component Container.” Name at least 3 component containers that ship now with the Windows Server Family.
  • What is a PID? How is it useful when troubleshooting a system?
  • How many processes can listen on a single TCP/IP port?
  • What is the GAC? What problem does it solve?

Mid-Level .NET Developer

  • Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.
  • Describe what an Interface is and how it’s different from a Class.
  • What is Reflection?
  • What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?
  • Are the type system represented by XmlSchema and the CLS isomorphic?
  • Conceptually, what is the difference between early-binding and late-binding?
  • Is using Assembly.Load a static reference or dynamic reference?
  • When would using Assembly.LoadFrom or Assembly.LoadFile be appropriate?
  • What is an Asssembly Qualified Name? Is it a filename? How is it different?
  • Is this valid? Assembly.Load(“foo.dll”);
  • How is a strongly-named assembly different from one that isn’t strongly-named?
  • Can DateTimes be null?
  • What is the JIT? What is NGEN? What are limitations and benefits of each?
  • How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?
  • What is the difference between Finalize() and Dispose()?
  • How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?
  • What does this useful command line do? tasklist /m “mscor*”
  • What is the difference between in-proc and out-of-proc?
  • What technology enables out-of-proc communication in .NET?
  • When you’re running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?

Senior Developers/Architects

  • What’s wrong with a line like this? DateTime.Parse(myString);
  • What are PDBs? Where must they be located for debugging to work?
  • What is cyclomatic complexity and why is it important?
  • Write a standard lock() plus “double check” to create a critical section around a variable access.
  • What is FullTrust? Do GAC’ed assemblies have FullTrust?
  • What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?
  • What does this do? gacutil /l | find /i “Corillian”
  • What does this do? sn -t foo.dll
  • What ports must be open for DCOM over a firewall? What is the purpose of Port 135?
  • Contrast OOP and SOA. What are tenets of each?
  • How does the XmlSerializer work? What ACL permissions does a process using it require?
  • Why is catch(Exception) almost always a bad idea?
  • What is the difference between Debug.Write and Trace.Write? When should each be used?
  • What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?
  • Does JITting occur per-assembly or per-method? How does this affect the working set?
  • Contrast the use of an abstract base class against an interface?
  • What is the difference between a.Equals(b) and a == b?
  • In the context of a comparison, what is object identity versus object equivalence?
  • How would one do a deep copy in .NET?
  • Explain current thinking around IClonable.
  • What is boxing?
  • Is string a value type or a reference type?
  • What is the significance of the “PropertySpecified” pattern used by the XmlSerializer? What problem does it attempt to solve?
  • Why are out parameters a bad idea in .NET? Are they?
  • Can attributes be placed on specific parameters to a method? Why is this useful?

C# Component Developers

  • Juxtapose the use of override with new. What is shadowing?
  • Explain the use of virtual, sealed, override, and abstract.
  • Explain the importance and use of each component of this string: Foo.Bar, Version=2.0.205.0, Culture=neutral, PublicKeyToken=593777ae2d274679d
  • Explain the differences between public, protected, private and internal.
  • What benefit do you get from using a Primary Interop Assembly (PIA)?
  • By what mechanism does NUnit know what methods to test?
  • What is the difference between: catch(Exception e){throw e;} and catch(Exception e){throw;}
  • What is the difference between typeof(foo) and myFoo.GetType()?
  • Explain what’s happening in the first constructor: public class c{ public c(string a) : this() {;}; public c() {;} } How is this construct useful?
  • What is this? Can this be used within a static method?

ASP.NET (UI) Developers

  • Describe how a browser-based Form POST becomes a Server-Side event like Button1_OnClick.
  • What is a PostBack?
  • What is ViewState? How is it encoded? Is it encrypted? Who uses ViewState?
  • What is the <machinekey> element and what two ASP.NET technologies is it used for?
  • What three Session State providers are available in ASP.NET 1.1? What are the pros and cons of each?
  • What is Web Gardening? How would using it affect a design?
  • Given one ASP.NET application, how many application objects does it have on a single proc box? A dual? A dual with Web Gardening enabled? How would this affect a design?
  • Are threads reused in ASP.NET between reqeusts? Does every HttpRequest get its own thread? Should you use Thread Local storage with ASP.NET?
  • Is the [ThreadStatic] attribute useful in ASP.NET? Are there side effects? Good or bad?
  • Give an example of how using an HttpHandler could simplify an existing design that serves Check Images from an .aspx page.
  • What kinds of events can an HttpModule subscribe to? What influence can they have on an implementation? What can be done without recompiling the ASP.NET Application?
  • Describe ways to present an arbitrary endpoint (URL) and route requests to that endpoint to ASP.NET.
  • Explain how cookies work. Give an example of Cookie abuse.
  • Explain the importance of HttpRequest.ValidateInput()?
  • What kind of data is passed via HTTP Headers?
  • Juxtapose the HTTP verbs GET and POST. What is HEAD?
  • Name and describe at least a half dozen HTTP Status Codes and what they express to the requesting client.
  • How does if-not-modified-since work? How can it be programmatically implemented with ASP.NET?
    Explain <@OutputCache%> and the usage of VaryByParam, VaryByHeader.
  • How does VaryByCustom work?
  • How would one implement ASP.NET HTML output caching, caching outgoing versions of pages generated via all values of q= except where q=5 (as in http://localhost/page.aspx?q=5)?

Developers using XML

  • What is the purpose of XML Namespaces?
  • When is the DOM appropriate for use? When is it not? Are there size limitations?
  • What is the WS-I Basic Profile and why is it important?
  • Write a small XML document that uses a default namespace and a qualified (prefixed) namespace. Include elements from both namespace.
  • What is the one fundamental difference between Elements and Attributes?
  • What is the difference between Well-Formed XML and Valid XML?
  • How would you validate XML using .NET?
  • Why is this almost always a bad idea? When is it a good idea? myXmlDocument.SelectNodes(“//mynode”);
  • Describe the difference between pull-style parsers (XmlReader) and eventing-readers (Sax)
  • What is the difference between XPathDocument and XmlDocument? Describe situations where one should be used over the other.
  • What is the difference between an XML “Fragment” and an XML “Document.”
  • What does it meant to say “the canonical” form of XML?
  • Why is the XML InfoSet specification different from the Xml DOM? What does the InfoSet attempt to solve?
  • Contrast DTDs versus XSDs. What are their similarities and differences? Which is preferred and why?
  • Does System.Xml support DTDs? How?
  • Can any XML Schema be represented as an object graph? Vice versa?

[Dev Tip] New Interview Questions for Senior Software Engineers

Here’s what I have so far.

  • What is something substantive that you’ve done to improve as a developer in your career?
  • Would you call yourself a craftsman (craftsperson) and what does that word mean to you?
  • Implement a <basic data structure> using <some language> on <paper|whiteboard|notepad>.
  • What is SOLID?
  • Why is the Single Responsibility Principle important?
  • What is Inversion of Control? How does that relate to dependency injection?
  • How does a 3 tier application differ from a 2 tier one?
  • Why are interfaces important?
  • What is the Repository pattern? The Factory Pattern? Why are patterns important?
  • What are some examples of anti-patterns?
  • Who are the Gang of Four? Why should you care?
  • How do the MVP, MVC, and MVVM patterns relate? When are they appropriate?
  • Explain the concept of Separation of Concerns and it’s pros and cons.
  • Name three primary attributes of object-oriented design. Describe what they mean and why they’re important.
  • Describe a pattern that is NOT the Factory Pattern? How is it used and when?
  • You have just been put in charge of a legacy code project with maintainability problems. What kind of things would you look to improve to get the project on a stable footing?
  • Show me a portfolio of all the applications you worked on, and tell me how you contributed to design them.
  • What are some alternate ways to store data other than a relational database? Why would you do that, and what are the trade-offs?
  • Explain the concept of convention over configuration, and talk about an example of convention over configuration you have seen in the wild.
  • Explain the differences between stateless and stateful systems, and impacts of state on parallelism.
  • Discuss the differences between Mocks and Stubs/Fakes and where you might use them (answers aren’t that important here, just the discussion that would ensue).
  • Discuss the concept of YAGNI and explain something you did recently that adhered to this practice.
  • Explain what is meant by a sandbox, why you would use one, and identify examples of sandboxes in the wild.
  • Concurrency
    • What’s the difference between Locking and Lockless (Optimistic and Pessimistic) concurrency models?
    • What kinds of problems can you hit with locking model? And a lockless model?
    • What trade offs do you have for resource contention?
    • How might a task-based model differ from a threaded model?
    • What’s the difference between asynchrony and concurrency?
  • Are you still writing code? Do you love it?
  • You’ve just been assigned to a project in a new technology how would you get started?
  • How does the addition of Service Orientation change systems? When is it appropriate to use?
  • What do you do to stay abreast of the latest technologies and tools?
  • What is the difference between “set” logic, and “procedural” logic. When would you use each one and why?
  • What Source Control systems have you worked with?
  • What is Continuous Integration?  Have you used it and why is it important?
  • Describe a software development life cycle that you’ve managed.
  • How do you react to people criticizing your code/documents?
  • Whose blogs or podcasts do you follow? Do you blog or podcast?
  • Tell me about some of your hobby projects that you’ve written in your off time.
  • What is the last programming book you read?
  • Describe, in as much detail as you think is relevant, as deeply as you can, what happens when I type “cnn.com” into a browser and press “Go”.
  • Describe the structure and contents of a design document, or a set of design documents, for a multi-tiered web application.
  • What’s so great about <cool web technology of the day>?
  • How can you stop your DBA from making off with a list of your users’ passwords?
  • What do you do when you get stuck with a problem you can’t solve?
  • If your database was under a lot of strain, what are the first few things you might consider to speed it up?
  • What is SQL injection?
  • What’s the difference between unit test and integration test?
  • Tell me about 3 times you failed.
  • What is Refactoring ? Have you used it and it is important? Name three common refactorings.
  • You have two computers, and you want to get data from one to the other. How could you do it?
  • Left to your own devices, what would you create?
  • Given Time, Cost, Client satisfaction and Best Practices, how will you prioritize them for a project you are working on? Explain why.
  • What’s the difference between a web server, web farm and web garden? How would your web application need to change for each?
  • What value do daily builds, automated testing, and peer reviews add to a project? What disadvantages are there?
  • What elements of OO design are most prone to abuse? How would you mitigate that?
  • When do you know your code is ready for production?
  • What’s YAGNI? Is this list of questions an example?
  • Describe to me some bad code you’ve read or inherited lately.

[Discovery] Những mục đích kỳ lạ khi huấn luyện các loài động vật

Trong suốt chiều dài lịch sử, con người chúng ta đã dần tiến hóa, trở thành loài động vật thống trị trên trái đất. Và tất nhiên, hầu hết các loài động vật khác đều đã bị lép vế và nằm trong vòng điều khiển của con người. Chúng ta đã nghiên cứu, tìm hiểu và sử dụng những đặc điểm riêng biệt của động vật để giúp ích cho cuộc sống của mình. Điển hình là việc chúng ta sử dụng ngựa để di chuyển và chở đồ, thuần hóa chó hoang thành chó giữ nhà, để làm cảnh hoặc nuôi gia súc gia cầm để lấy được thực phẩm cho cuộc sống.

Rõ ràng, những việc mà động vật đã giúp cho cuộc sống của con người chúng ta là rất rất nhiều, khó có thể kể ra hết được. Trong số đó, có rất nhiều việc diễn ra hàng ngày, bình thường, nhưng cũng có rất nhiều điều khá đặc biệt và kì lạ. Sau đây, hãy cùng Genk điểm ra một số nhiệm vụ kì lạ và khó hiểu nhất mà con người đã sử dụng động vật để làm trong lịch sử.

Sử dụng đom đóm trong thế chiến thứ nh

Những mục đích kỳ lạ khi huấn luyện các loài động vật

Đom đóm hay bọ phát sáng là những loài côn trùng cánh cứng nhỏ được gọi chung là họ Đom đóm (Lampyridae) có khả năng phát quang. Đom đóm là động vật tiêu biểu cho vùng ôn đới mặc dù phần lớn các loài sống ở vùng nhiệt và cận nhiệt đới (khoảng 2000 loài). Chúng là những sinh vật có tập tính hoạt động về ban đêm, con đực thường có cánh và bay vào những đêm đầu mùa hạ. Nhiều loài, con cái không có cánh. Con đực, con cái và ấu trùng phát ra ánh sáng lạnh và thường có màu đỏ cam hay vàng xanh (bước sóng 510 – 670 nm); một số loài thậm chí trứng cũng phát quang. Người ta cho rằng, ánh sáng giữ vai trò quan trọng trong tập tính sinh sản của chúng với mục đích hấp dẫn con khác giới. Bình thường khả năng phát sáng của đom đóm cũng đã được biết tới rất nhiều và chúng thường xuất hiện trong phim ảnh như một hình ảnh đẹp và nên thơ.

Tuy nhiên ít ai biết được rằng, trong thời kỳ chiến tranh thế giới lần thứ nhất, loài động vật kì thú này đã thực sự được sử dụng khả năng phát sáng của mình cho mục đích quân sự của loài người. Các binh sĩ Anh hồi bấy giờ đã phải đối mặt với vấn đề phải đọc bản đồ và các giấy tờ trong bóng tối. Các chiến hào tất nhiên không thể được trang bị ánh sáng nhân tạo nổi bật nào bởi nó sẽ thu hút và biến khu vực đó thành mục tiêu tấn công cho kẻ thù. Công nghệ vào thời điểm đó cũng chưa phát triển đủ để các binh sĩ có một phương tiện tối tân nào để có được các đốm sáng cần dùng. Cuối cùng, quân đội Anh đã đưa ra phương pháp sử dụng đom đóm. Những chú đom đóm đã cung cấp đủ ánh sáng cho các binh sĩ đọc bản đồ hiệu quả mà cũng không làm cho kẻ thù phát hiện ra bởi khoảng cách lớn. Và nhờ vào khả năng sinh sản mạnh mẽ của loài này, nguồn cung đom đóm cũng không mấy khan hiếm. Nó trở thành một công cụ ánh sáng hoàn hảo trên tiền tuyến.

Rõ ràng những chú đom đóm đã thực sự có ích. Chúng còn được vinh danh cùng một số động vật khác có đóng góp trong chiến tranh tại một đài tưởng niệm ở London khánh thành vào năm 2004.

Sử dụng chồn sương làm thợ điện

Những mục đích kỳ lạ khi huấn luyện các loài động vật

Chồn sương là một loại chồn bắt nguồn từ phân nhánh của loài Mustela putorius. Đây là động vật đã được con người thuần hóa để trở thành vật nuôi. Chồn sương là một loài ăn thịt kích thước vừa phải. Chồn sương có lông màu nâu, đen, trắng hoặc lang. Một trong những con mồi của loài chồn này là thỏ. Loài này đã được thuần dưỡng để làm cảnh cách đây nhiều năm. Tại Mỹ, số lượng người nuôichồn làm cảnh chỉ đứng sau số người nuôi chó và mèo. Loài này thông minh trung thành, thể hình và khuôn mặt dễ thương, tính tình hiếu động nghịch ngợm, Chồn là loài vật nuôi thích hợp nhất với những người chủ trong thành phố, ngắm nhìn chúng hoạt động đùa nghịch. Với thói quen và trí thông minh và chỉ đi vệ sinh 1 chỗ cố định vào 1 khoảng thời gian nhất định. Nhưng trong quá khứ, ngoài việc làm vật nuôi, chú chồn này đã từng được hãng máy bay nổi tiếng Boeing tận dụng làm … thợ điện cực kì hiệu quả.

Hệ thống dây điện vốn dĩ luôn là một vấn đề nan giải, chúng thường loằng ngoằng và được đặt ở những vị trí chật chội. Ở một số địa hình khó cũng như trong một số hoàn cảnh, thợ điện không thể tiếp cận được đến vị trí thuận lợi, điển hình là trên những chiếc máy bay phức tạp. Tuy nhiên hãng Boeing đã thành công khi nghĩ đến ý tưởng tận dụng loài chồn sương. Họ đã khắc phục vấn đề này bằng cách gắn dây cáp vào người con chồn sương rồi đặt thức ăn của chúng ở nơi cần nối. Chồn sương mang dây cáp đến bất cứ nơi nào cần lắp dây diện trên máy bay. Ý tưởng này đã được Boeing sử dụng từ năm 1960, và đến nay nó vẫn được sử dụng. Năm 2004 loài này cũng đã giúp trong việc đặt dây cáp dành cho một buổi ca nhạc.

Ong giúp dò bom mìn

Những mục đích kỳ lạ khi huấn luyện các loài động vật

Các cơ quan thực thi pháp luật trên thế giới từ lâu đã sử dụng động vật để phát hiện bom và chất nổ tại trong một số địa điểm có an ninh cao. Tuy nhiên, loài động vật được sử dụng trong những trường hợp này thường là vì khả năng đánh hơi nhạy bén của chúng. Cho đến hiện tại, các nhà nghiên cứu tại Phòng thí nghiệm Quốc gia Los Alamos đã phát hiện ra loài sinh vật có khả năng dò mìn hoàn toàn tương xứng hoặc có thể mạnh mẽ hơn cả loài chó – đó chính là những chú ong

Họ đã phát hiện ra rằng những chú ong có thể phát hiện được chất nổ sau khi được huấn luyện. Chúng được huấn luyện sao cho đạt được phản xạ có điều kiện: liên hệ một mùi nào đó chẳng hạn như mùi thuốc nổ TNT, DNT và RDX với một phần thưởng. Trong các khóa huấn luyện thực tế, máy cung cấp nước đường và một chút thuốc nổ được đặt gần tổ ong. Khi ong uống nước đường, chúng bắt đầu liên tưởng mùi của thuốc nổ với nguồn thức ăn. Khi lên đường làm nhiệm vụ, ong sẽ tìm kiếm những mùi tương tự ở một khu vực và tiếp tục tìm kiếm trong nhiều giờ hoặc nhiều ngày.

Ong cũng huấn luyện nhau. Chẳng hạn như nếu cần nhiều tổ ong để dò một khu vực rộng lớn, các chuyên gia chỉ cần huấn luyện một tổ ong. Ong từ đàn được huấn luyện sẽ tự tuyển dụng và dạy những con khác. Ngoài việc dò mìn, ong còn báo hiệu về những điều bất bình thường trong môi trường, bao gồm cả các cuộc tấn công vũ khí hóa học. Các mẫu sáp, mật và phấn hoa được thu thập từ tổ ong cũng tiết lộ những chất ô nhiễm trong một khu vực nào đó. Điểm có lợi hơn so với loài chó của ong chính là về kích cỡ tí hon của chúng, các nghi phạm bị điều tra giữ chất nổ chắc chắn sẽ nghi ngờ những chú chó nghiệp vụ nhưng có lẽ khó mà dè chừng được với những chú ong. Thêm vào đó,ong có thể làm việc trong một không gian nhỏ và phức tạp

Dùng quạ để tìm thấy đất liền khi đi trên biển

Những mục đích kỳ lạ khi huấn luyện các loài động vật

Quạ có khoảng 40 loài có kích thước khác nhau. Một số loài trong chi này có trí thông minh cao. Một con quạ mỏ nhỏ đã được ghi nhận là biết đập vỡ hạt bằng cách đặt nó trên lối đi bộ ngang qua đường, để cho ô tô đi qua làm vỡ vỏ, chờ cho đèn báo giao thông chuyển sang đỏ và sau đó thu lấy nhân hột một cách an toàn. C

ác thành viên của họ Quạ cũng biết theo dõi các loài chim khác, ghi nhớ nơi chúng cất giấu thức ăn và sau đó mò tới khi con chim kia rời khỏi nơi đó. Chim họ Quạ cũng di chuyển thức ăn của chính chúng giữa các nơi cất giấu để tránh bị ăn trộm, nhưng chỉ khi nếu chúng trước đó đã từng bị trộm cắp. Khả năng cất giấu thức ăn đòi hỏi trí nhớ về không gian rất chính xác.

Và chính nhờ khả năng này mà nó đã được người Viking sử dụng khá nhiều trong việc tìm ra vùng đất cần đến. Là một nền văn minh trên biển, những người Viking sẽ dành nhiều thời gian trên mặt nước và hiểu biết nhiều về biển cả. Tuy nhiên, đất liền lại là một nhược điểm, họ khó mà xác định được đâu là các khu vực đất liền và điều này có vẻ như gây ra không ít nguy hiểm.

Để khắc phục điều đó, người Viking thường mang theo một con quạ lên tàu và thả nó khi trên biển. Nếu con quạ thấy vùng đất, nó sẽ ngay lập tức bay theo hướng đó và người ta sẽ theo nó vào bờ. Còn nếu không có đất đậu, con chim sẽ quay trở lại tàu để tránh nước. Có những câu chuyện tương truyền rằng vùng đất Iceland đã được tìm ra bằng phương thức này.

Tham khảo: Toptenz

[Startup] Thị trường thương mại điện tử Việt Nam qua góc nhìn của CEO Sieumua

thi-truong-thuong-mai-dien-tu-viet-nam-qua-goc-nhin-cua-ceo-sieumua-1Thị trường thương mại điện tử (TMĐT) Việt Nam trong thời gian gần đây đang phát triển khá sôi động, với sự góp mặt của hàng trăm doanh nghiệp trong và ngoài nước. Cùng với sự hỗ trợ của nền tảng mobile trong kỷ nguyên internet, việc các doanh nghiệp dịch chuyển công việc kinh doanh sang môi trường online là xu thế tất yếu.

Tuy nhiên, thực hư thị trường TMĐT Việt Nam như thế nào? Đó phải là mảnh đất màu mỡ để các startup bắt đầu xây dựng nền móng cho mình hay không? Những khó khăn gì sẽ chờ đợi khi các startup muốn tham gia vào thị trường này?

Tech in Asia đã có buổi phỏng vấn với anh Phan Văn Sơn, CEO của Sieumua để cùng làm rõ bức tranh toàn cảnh về thị trường TMĐT Việt Nam trong thời gian qua.

Anh có thể cho nhận xét tổng quan thị trường TMĐT ở Việt Nam trong thời gian qua?

Có thể nói, thị trường TMĐT ở Việt Nam bắt đầu phát triển từ khoảng năm 2009, bởi vì trước đó hầu hết người Việt Nam đều chưa có khái niệm mua hàng trực tuyến. Sau đó vào năm 2010 thì thị trường TMĐT thực sự bùng phát, với sự góp mặt của rất nhiều doanh nghiệp tham gia cùng một lúc, khiến thị trường phát triển khủng khiếp.

Tuy nhiên, đây là thời kỳ của nhiều doanh nghiệp làm ăn “chộp giật”, chỉ làm lấy số lượng mà không quan tâm tới chất lượng sản phẩm, có doanh nghiệp một ngày có thể thực hiện vài ngàn đơn hàng, nhưng sản phẩm mang lại không được như mong đợi của khách hàng. Đồng thời hầu hết các doanh nghiệp TMĐT chỉ nghĩ tới lợi nhuận và chỉ tìm cách bảo vệ lợi ích của mình chứ không nghĩ đến lợi ích cho khách hàng.

Điều nay gây ra một hệ quả nghiêm trọng là khách hàng mất niềm tin vào các doanh nghiệp TMĐT, do đó năm 2012 đánh dấu sự ra đi của rất nhiều doanh nghiệp TMĐT.

Năm 2012 đánh dấu thời kỳ sụp đổ của các doanh nghiệp TMĐT ở Việt Nam.

Hiện nay, Việt Nam có khoảng 35 triệu người thường xuyên sử dụng internet, trong đó có khoảng 10%, tức là khoảng 3,5 triệu người có thói quen mua hàng trực tuyến, có thể thấy thị trường TMĐT ở Việt Nam còn nhiều tiềm năng, nhưng để có thể đạt được thành công thì còn rất nhiều khó khăn.

Anh có thể cho biết những khó khăn mà các doanh nghiệp gặp phải trong thị trường TMĐT?

TMĐT là một ngành kinh doanh khá độc lập, không phải ai giỏi kinh doanh truyền thống đều có thể nhảy sang TMĐT. Nhiều người đứng ngoài cứ nghĩ TMĐT đơn giản, chỉ cần làm 1 website là có thể kinh doanh được, tuy nhiên không phải như vậy. Làm TMĐT là phải biết về công nghệ, phải biết cách quản lý các quy trình onilne, phải biết về AdWords, SEO…

Đối với bất kỳ thị trường nào, điều quan trọng nhất là phải tạo được được niềm tin của khách hàng. Sau thời kỳ ra đi của rất nhiều doanh nghiệp TMĐT, khách hàng bị mất niền tin vào TMĐT. Do đó hiện nay, cần rất nhiều thời gian tích luỹ để tạo dựng lại uy tín của các doanh nghiệp cũng như niềm tin của khách hàng vào TMĐT. Hơn nữa, để có thể tạo dựng một nền tảng vững chắc và trở thành người đi đầu là một vấn đề rất lớn, doanh nghiệp cần phải duy trì niềm tin này trong một thời gian dài.

Thứ hai, hiện nay TMĐT bị cạnh tranh rất gay gắt. Có thể thấy là hiện giờ ai cũng có thể bán hàng trên Facebook được, do vậy khách hàng rất dễ dàng trong việc tìm kiếm và có rất nhiều lựa chọn mua hàng. Nhiều khách hàng còn đặt đơn hàng của 2-3 doanh nghiệp, ai giao nhanh hơn thì mua của người đó khiến giao dịch bị huỷ rất nhiều.

Hơn nữa thị trường Việt Nam hiện nay đang có sự góp mặt của rất nhiều doanh nghiệp nước ngoài hoặc được đầu tư từ nước ngoài. Những doanh nghiệp này đầu tư vào thương hiệu rất lớn, chăm sóc khách hàng tốt, thậm chí họ còn chấp nhận lỗ để mở rộng thị trường và tăng lượng người dùng.

Thứ ba là người tiêu dùng Việt Nam chưa có thói quen thanh toán trực tuyến. Mặc dù công nghệ dành cho thanh toán trực tuyến ở Việt Nam đã sẵn sàng khoảng 5 năm nay, nhưng người dùng Việt Nam vẫn muốn thanh toán dưới hình thức COD (thanh toán khi nhận hàng). Điều này khiến các doanh nghiệp TMĐT tốn rất nhiều chi phí vận hành như: chi phí vận chuyển, chi phí marketing, nhân sự. Nhiều đơn hàng giao thành công rồi vẫn bị khách hàng huỷ khiến chi phí phát sinh tăng cao.

Người dùng Việt Nam vẫn chưa có thói quen thanh toán trực tuyến.

Hơn nữa người dùng Việt Nam hiện nay vẫn quen “xem, sờ, thử” nên nhiều doanh nghiệp TMĐT phải chấp nhận mở cả cửa hàng outlet để phục vụ nhu cầu offline của khách hàng. Không những vậy, nhiều doanh nghiệp, kể cả doanh nghiệp nước ngoài để tăng giá trị thương hiệu có thể mở bán hàng chục ngàn sản phẩm, nhưng lại không thể bao quát hết được, thực tế chỉ có khoảng 5.000 – 7.000 sản phẩm, chưa kể những đơn hàng bị huỷ khiến lượng giao dịch “ảo” tăng lên nhiều lần. Điều này dễ gây ra ảo tưởng cho những startup đang muốn tham gia vào thị trường TMĐT.

Thực tế là không phải ai cũng có thể làm TMĐT trong thời điểm này.

Vậy theo anh, đâu là giải pháp cho các doanh nghiệp TMĐT Việt Nam?

Làm TMĐT là phải làm từng bước một, những năm đầu tiên chỉ cần một vài người thực sự giỏi để tạo dựng mô hình và thiết lập chiến lược doanh nghiệp, sau đó, khi doanh nghiệp đã đứng vững rồi thì mới cần những đội ngũ giỏi khác để tối ưu hoá dần việc kinh doanh và phát triển doanh nghiệp. Không ai có thể hiểu về thị trường ngay được.

Tiếp theo là các doanh nghiệp TMĐT phải tối ưu hoá chi phí và khuyến khích thanh toán trực tuyến như: miễn phí vận chuyển, hoặc giảm 5% cho những đơn hàng thanh toán trực tuyến…

Bởi vì chỉ có thanh toán trực tuyến mới đảm bảo lợi nhuận cho doanh nghiệp, giúp dòng tiền của doanh nghiệp luân chuyển nhanh hơn, tiết kiệm chi phí và đảm bảo thành công các giao dịch, tỷ lệ khách hàng huỷ đơn hàng ít hơn.

Đồng thời phải tạo được niềm tin và tính chuyên biệt cho khách hàng. Ví dụ như Sieumua lựa chọn chuyên về kinh doanh thời trang, bởi vì thị trường rất lớn, nhiều đối tượng khách hàng, nếu cung cấp sản phẩm và dịch vụ tốt, mọi người sẽ quay lại. Thời trang là mặt hàng hôm nay mua rồi, ngày mai vẫn có thể mua tiếp, không giống như các sản phẩm điện tử, điện máy, nhiều năm sau người dùng vẫn chưa có nhu cầu mua lại.

Nói chung TMĐT ở Việt Nam hiện nay đang rất khó khăn, thực ra không một doanh nghiệp TMĐT nào dám nói chắc gì về tương lai 5-10 năm tới. Tuy nhiên, quan điểm của cá nhân tôi cho rằng:

Phải đi theo mô hình khó và khi vượt được qua nó rồi thì bạn mới phát triển bền vững. Bởi vì đi theo các mô hình dễ dàng thì sức cạnh tranh càng cao, thành công càng trở nên bấp bênh.

Xin cảm ơn anh vì buổi phỏng vấn hôm nay!

(Biên tập bởi Quyen Quyen)