23/01/2017

C++ for C# developers - code like in Google

Home


Title: Elephant Retirement Camp in the vicinity of Chiang Mai, Source: own resources, Authors: Agnieszka and Michał Komorowscy

In the post Nuget in C++ rulez I wrote that I returned to programming in C++. It is like a new world for me but it's better and better. I'm even reminding myself things that I learned many years ago so it's not bad with me ;) Recently, I've discovered a C++ alternative for .NET StyleCop. StyleCop is a tool that analyses C# code in order to check if it is consistent with given rules and good practices. What is obvious there is a similar thing for C++ I'm talking about a tool called CppLint that was created by Google. It's written in Python and is fairly easy in use. However, please note that CodeLint requires the old Python 2.7. I tried and it won't work with Python 3.5.

When I run CppLint on my code it turned out that my habits from C# don't fit to C++ world according to Google. Here is an example of Hello Word written in C++ but in C# style.
#include <iostream>

namespace sample 
{
    class HelloWorld
    {
        public:
            void Fun()
            {
                std::cout << "Hello World Everyone!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
            }
    };
}

int main()
{
  sample::HelloWorld hw = sample::HelloWorld();
  hw.Fun();
  
  return 0;
}
If we verify this code, we will get the following errors:
a.cpp:0:  No copyright message found.  You should have a line: "Copyright [year] <Copyright Owner>"  [legal/copyright] [5]
a.cpp:3:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
a.cpp:4:  { should almost always be at the end of the previous line  [whitespace/braces] [4]
a.cpp:5:  Do not indent within a namespace  [runtime/indentation_namespace] [4]
a.cpp:6:  { should almost always be at the end of the previous line  [whitespace/braces] [4]
a.cpp:7:  public: should be indented +1 space inside class HelloWorld  [whitespace/indent] [3]
a.cpp:9:  { should almost always be at the end of the previous line  [whitespace/braces] [4]
a.cpp:10:  Lines should be <= 80 characters long  [whitespace/line_length] [2]
a.cpp:13:  Namespace should be terminated with "// namespace sample"  [readability/namespace] [5]
a.cpp:16:  { should almost always be at the end of the previous line  [whitespace/braces] [4]
a.cpp:19:  Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/end_of_line] [4]
a.cpp:21:  Could not find a newline character at the end of the file.  [whitespace/ending_newline] [5]
At the beginning of each line we have the line number where an error was detected. The number in square brackets at the end of each line informs you how confident CppLint is about each error i.e. 1 - it may be a false positive, 5 - extremely confident. In order to fix all these problems I did the following things:
  • Added Copyright 2016 Michał Komorowski.
  • Removed whitespaces at the end of lines.
  • Added a new line at the end of file.
  • Added a comment // namespace sample
  • Move curly braces. This one I don't like the most.
  • Break a too long line. It's also a little bit strange to me. 80 doesn't seem to be a lot. However, shorter lines makes working with multiple windows easier (see also this answer).
Then I run a tool again and I got some new errors:
a.cpp:6:  Do not indent within a namespace  [runtime/indentation_namespace] [4]
a.cpp:7:  public: should be indented +1 space inside class HelloWorld  [whitespace/indent] [3]
I also fixed them and the final version of Hello Worlds compliant with Google rules looks as follows: Here is the correct version:
// Copyright 2016 Michal Komorowski

#include <iostream>

namespace sample {
class HelloWorld {
 public:
  void Fun() {
    std::cout
      << "Hello World Everyone!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
      << std::endl;
  }
};
}  // namespace sample

int main() {
  sample::HelloWorld hw = sample::HelloWorld();
  hw.Fun();
  return 0;
}

It's worth adding that CppLint has many configuration options for example you can disable some rules if you don't agree with them or change the maximum allowed length of a line (default is 80). Options can be also read from the configuration file CPPLINT.cfg.

16/01/2017

When Excel is better than machine learning?

Home


Title: Ruins of a castle in southern Poland, Source: own resources, Authors: Agnieszka and Michał Komorowscy

I can bet that some of you think that I'm crazy because I'm saying such blasphemies! Surely everyone knows that Excel is not for real developers ;) If you think so, I'll tell you a short story.

09/01/2017

Yerba Mate to the rescue

Home



I heard about Yerba Mate many years ago. It must have been in a television program run by quite famous Polish journalist, writer, satirist and traveler Wojciech Cejrowski who is also a popularizer of this drink. However, it took some time until I decided to give it a try. Now it is one of basic "tool" in my developer tool box. Why? This post explains it.

03/01/2017

Is it possible to do PhD and work full time?

Home


Source: own resources, Authors: Agnieszka and Michał Komorowscy

I decided to return to my series about Ph.D. studies and write about sharing a time between a job in the industry and scientific work. According to my experience it is quite a common scheme here in Poland (at least if we talk about the computer science). A vast majority of my colleagues had additional job during their Ph.D. studies. In this post I'll try to answer some question on this topic.

A short clarification. By working in the industry I uderstand engineering/technical work that in general doesn't have scientific part. However, I'm aware that there are positions in the industry that required scientific qualification and I'll also write a few words about it.

Why a Ph.D. student may want to work instead of focusing on his/her research?

Well the answer is trivial and it is money. Let's start with the fact that many MSc / BsC students work during their studies. It means that they may have 2, 3 years of experience when they start Ph.D. studies (I assume here that they start Ph.D. just after MSc). With such an experience their salary in the industry could be 2x, 3x, 4x times higher than on the university.

Is it feasible at all to work full time and finish Ph.D. Studies?

Short answer is yes it is possible. I was working full time for almost all my Ph.D. studies and I did it.

What about money from grants and additional projects on the university?

Someone may say that Ph.D. students can also earn additional money by working for their doctoral advisors. It's true but it depends strongly on your advisor. Some of them have grants, projects etc. and will allow you to earn additional money and sometimes this are quite good money. However, not all advisors have such possibilities. Besides you have to remember that grants/projects will end at some point. So you may have good money for X months and then poor money for another Y months.

Another option is to get a grant on your own. There are even dedicated funds for young scientists. However, I couldn't say much about that because I didn't have such a grant. The problem may be that in order to get such a grant you have to have good results. And in order to have good results you should focus on your research. And in order to focus on the research you can't have a full time job. But if you don't have a full time job, you'll have to live for considerable smaller amount of money...

How did a full time job affect your scientific work?

I'm convinced that my Ph.D. thesis would have been better if hadn't worked full time. I have no doubts here. It may sound trivial but the main problem is that scientific work required a lot of innovative thinking, much more than average programming work. And this kind of thinking is difficult after a day of work not to mention about a time for family.

I have one more, not so obvious, observation. I think that because of my full time job in the industry my Ph.D. thesis has engineering inclination. Is it good or bad? I'd say that it depends. We have to remember that Ph.D. is mainly about doing science and engineering part is less important.

I know the case when Ph.D. student didn't defend his thesis because it was too technical! On the another hand if you know the industry your work may be potentially more useful or it may be easier to find practical applications. To sum up it is important to preserve a proper balance between engineering and science with the focus on the latter.

Last but not least. If you work full time during Ph.D. studies you may not have time to take part in additional courses, trainings... that are dedicated to Ph.D. students.

What kind of job will be the best for Ph.D. student if any?

At the beginning of my Ph.D. studies I was working part time. It was a very good idea. I simply had more time for my research. So, if you need to work I strongly recommend you to consider the part time job. The problem is that not every employer will agree for that.

Of course a full time job can sometimes help you in doing Ph.D. i.e.:
  • when it is somehow related to your area of research
  • if the industry is paying you for doing research
  • if the industry is paying you for doing Ph.D.
In this situation you actually don't have 2 jobs but ideally only 1 job, or maybe 1.5 but still it's better than 2. Unfortunately, according to my experience it is difficult to find such a job.

Do you have tips for Ph.D. students who want to work in the industry?

Except what I've already written it'll be good to find a job with flexible working hours. Thanks to that you will be able to go to the university, meet with an advisor etc. without problems. Besides avoid overtime like the plague. It's another think that can kill your scientific work.

I also recommend to have a rule that every week we have to do something related to our Ph.D. It could be reading some articles, doing an experiment, implementing a tool... It's important to do that despite everything. Thanks to that you will constantly see some progress and you will not lose sight of the main objective i.e. Ph.D.

The last advice might be surprising because I did something different ;)

If you seriously think about the scientific career forget about working in the industry. The only exception is if a job in the industry is related to your scientific work.

26/12/2016

Migration to Nuget V3

Home


Source: own resources, Authors: Agnieszka and Michał Komorowscy

Sometime ago I wrote a post about My struggels with GitHub, Subtrees and Nuget and Joseph suggested me another solution of my problem in the comments i.e. to switch to Nuget V3. A few days ago I finally found time to give it a try. I started by reading this tutorial/post written by Oren Novotny. It's really a good source of knowledge so I'll not describe the whole process again. However, I encountered 3 problems that weren't described and I'll briefly write about them.

Project.json vs Project.config

A new Nuget uses project.json file instead of the old project.config so I started with adding this new file to all projects. Then I moved packages from the old files to the new ones. In the next step I reloaded all the projects just to be sure that VS will see changes. After that I built the solution to see if it works and it worked. Finally, I made a commit and pushed my changes. And here comes a problem. In a few minutes I got an e-mail from my Azure (hosted) build controller that a build has just failed.

§ Error: C:\a\_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.24\node_modules\nuget-task-common\NuGet\3.3.0\NuGet.exe failed with return code: 1
§ Packages failed to install

The source of a problem was apparently a conflict between project.config and project.json so I just removed the former from the projects.

Naming problem

It is not everything. The next problem looked in the following way:

Failed to resolve conflicts for .NETFramework,Version=v4.6 (win).
Unable to satisfy conflicting requests for 'MVVMLight': project/MVVMLight (>= 1.0.0) (via project/MVVMLight 1.0.0)
Unable to satisfy conflicting requests for 'CommonServiceLocator': CommonServiceLocator (>= 1.3.0) (via project/MVVMLight 1.0.0)
Unable to satisfy conflicting requests for 'MvvmLight': MvvmLight (>= 5.1.1) (via project/MVVMLight 1.0.0)...

This time the fix was also easy. Nuget V3 doesn't like if the projects in the solution have exactly the same names as packages! In my solution I had MVVMLight project which is my playground for MVVMLight package. I renamed in to MVVMLightTest.

Last but not the least

After migration to Nuget V3 I had to deal with one more problem and again I didn't observe it locally but only when building on Azure (hosted) build controller. In the build log I found the following error:

The OutputPath property is not set for project 'LanguageTrainer.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='x86'.

And it turned out that in some csproj files I had the following condition:

<Platform Condition=" '$(Platform)' == '' ">x86</Platform>

It says that if the platform is not specified for a given build then use x86. At the same time these csproj didn't contain configuration, including the problematic OutputPath, for x86. To fix a problem I simply changed x86 to AnyCPU.