Perl 6 Hands-On Workshop: Weatherapp (Part 3)

Read this article on Perl6.Party

Be sure to read Part 1 and Part 2 of this workshop first.

There is black box testing, glass box testing, unit testing, integration testing, functional testing, system testing, end-to-end testing, sanity testing, regression testing, acceptance testing, load testing, stress testing, performance testing, usability testing, and many more types of testing.

I'll leave it for people with thicker glasses to explain all of the types. Today, we'll write tests that ensure our weather reporting module works as expected, and as a bonus, you get to pick your own label for what type of tests these are. Let's dive in!

TDD

TDD (Test-Driven Development) is where you write a bunch of tests before you write the actual code, ensure they fail—because code to satisfy them isn't there yet—and then you write code until the tests succeed. Now you can safely refactor your code or add new features without worrying you'll break something. Rinse and repeat.

Speak Up Or Step Away

I recently attended #ILookLikeAnEngManager at OSCON 2016, in Austin, Texas. It really raised my consciousness about sexism in technology. I naively thought that world-culture as a whole was discouraging women from science, engineering, and technology. It literally hadn't occurred to me that the technology industry was pushing back on women.

I was outraged! When I got home and "informed" my wife she calmly, and patiently asked me how I could possibly not know that. It has been a rough path of introspection since then.

So how did I not know?

  • I'm a man and didn't have any recent exposure to sexism in the workplace ("sexism? that's so 1990's!").
  • I like working with women.
  • I naively thought that working for an "equal-opportunity employer" implicitly demands that we be equal-opportunity employees.
  • The most-competent software developer on my team happens to be a woman, and I have an excellent team.
  • The women in my life perceive me as non-sexist.

Perl 5 Porters Mailing List Summary: May 19th-24th

Hey everyone,

Following is the p5p (Perl 5 Porters) mailing list summary for the past week and a bit. Enjoy!

Perl 6 Hands-On Workshop: Weatherapp (Part 2)

Read this article on Perl6.Party

Be sure to read Part 1 of this workshop first.

Imagine writing 10,000 lines of code and then throwing it all away. Turns out when the client said "easy to use," they meant being able to access the app without a password, but you took it to mean a "smart" UI that figures out user's setup and stores it together with their account information. Ouch.

The last largish piece of code where I didn't bother writing design docs was 948 lines of code and documentation. That doesn't include a couple of supporting plugins and programs I wrote using it. I had to blow it all up and re-start from scratch. There weren't any picky clients involved. The client was me and in the first 10 seconds of using that code in a real program, I realized it sucked. Don't be like me.

Complicated joins with DBIx::Class

DBIx::Class is a great way to hide database interactions in your Perl classes. However, something that you might find easy in normal DBI queries can seem hard in DBIx::Class, because you lack direct access to the SQL. Take for example the following query:

select dayparts.name from eventtyperooms 
  join slots on (eventtyperooms.room_id=slots.room_id) 
  join dayparts on (slots.daypart_id = dayparts.id) 
  where slots.is_reserved=0 and eventtyperooms.eventtype_id='E375219C-CDBB-11E5-8739-AFC57843E904' 
  group by slots.daypart_id 
  order by dayparts.start_date asc;

There are lots of joins going on here and not all of them are on primary keys. Plus we’ve got some other qualifiers in there. This is where search_related() can come to the rescue.

$eventtype->search_related('eventtyperooms')
  ->search_related('slots', {'slots.is_reserved' => 0})
  ->search_related('daypart')
  ->search(undef, {
    group_by => 'slots.daypart_id', 
    order_by => 'daypart.start_date'
  });

The above code will generate the following query:

SELECT `daypart`.`id`, `daypart`.`name`, `daypart`.`is_locked`, `daypart`.`start_date`
  FROM `eventtyperooms` `me` 
  JOIN `slots` `slots` 
    ON `slots`.`room_id` = `me`.`room_id` 
  JOIN `dayparts` `daypart` 
    ON `daypart`.`id` = `slots`.`daypart_id` 
WHERE `me`.`eventtype_id` = 'E375219C-CDBB-11E5-8739-AFC57843E904' AND `slots`.`is_reserved` = '0' 
GROUP BY `slots`.`daypart_id` 
ORDER BY `daypart`.`start_date`

This allows you to use all the existing relationships you’ve set up in your schema to do complex joins.

[From my blog.]

Hiring in Sydney Australia

Staples is hiring Perl developers like crazy here in Sydney Australia.

I understand they are running a linux+perl+oracle environment, with the usual periphery of open source to boot.

More details and apply at: http://buff.ly/1TImJxp

There are a few other companies hiring too, check them out at https://www.facebook.com/sydneypm

(Disclaimer: I am not employed by Staples now or prior. I am just helping people pay their mortgages etc)

A Date with CPAN, Part 10: Cleanliness Is Next to Timeliness

[This is a post in my latest long-ass series.  You may want to begin at the beginning.  I do not promise that the next post in the series will be next week.  Just that I will eventually finish it, someday.  Unless I get hit by a bus.

IMPORTANT NOTE!  When I provide you links to code on GitHub, I’m giving you links to particular commits.  This allows me to show you the code as it was at the time the blog post was written and insures that the code references will make sense in the context of this post.  Just be aware that the latest version of the code may be very different.]


Last time I rearranged our UI to be (hopefully) a bit more intuitive.  This time I want to clean up the remainder of those pesky CPAN Testers failures on our way to the next solid release.

FFI::Platypus is interesting. It seems like real FFI module for Perl 5.

FFI::Platypus is interesting. It seems like real FFI module for Perl 5.

FFI is foreign function interface. This is a little slow than XS, but you can call C/C++ library without C code.

I saw some FFI module for perl 5, FFI, or FFI::Raw, but not enough to create C extension flexibly.

FFI::Platypus seems like excelent module because you can call any C/C++ library using its features.

FFI::Platypus/CPAN

I try some example. All work well.

  use FFI::Platypus;
 
  my $ffi = FFI::Platypus->new;
  $ffi->lib(undef); # search libc

  # call dynamically
  $ffi->function( puts => ['string'] => 'int' )->call("hello world");

  # attach as a xsub and call (much faster)
  $ffi->attach( puts => ['string'] => 'int' );
  puts("hello world");

You can also create C structure in Perl code by using "record_layout" method.

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is hosted by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.