1
00:00:00,910 --> 00:00:04,120
My name is Ashish Mahabal, and we'll
be continuing with the module on best

2
00:00:04,120 --> 00:00:07,560
programming practices,
the last part of it.

3
00:00:07,560 --> 00:00:10,380
So today we'll be seeing a little
bit about portfolio building.

4
00:00:10,380 --> 00:00:14,090
But before that,
just a quick word about metaprogramming.

5
00:00:14,090 --> 00:00:15,690
So what that means is that,

6
00:00:15,690 --> 00:00:19,880
you want, you will want to separate
some configuration files, which have

7
00:00:19,880 --> 00:00:24,590
specific data which can be changed by
either the user or you, yourself will be

8
00:00:24,590 --> 00:00:28,840
changing that later that allows you to
have all the abstraction in your code.

9
00:00:28,840 --> 00:00:31,660
And then that can be separated, which
doesn't have to be touched again, and

10
00:00:31,660 --> 00:00:36,560
again, or perhaps even ever
once you have the metadata, or

11
00:00:36,560 --> 00:00:39,720
the bits that need to be changed
in separate configuration files.

12
00:00:39,720 --> 00:00:44,010
So you should have those configuration
files for various things that those can be

13
00:00:44,010 --> 00:00:47,995
plain text files, and
you can change that very easily, later on.

14
00:00:47,995 --> 00:00:51,540
[COUGH] When it comes to
portfolio building, what I

15
00:00:51,540 --> 00:00:56,360
would like to advise is that you should
have as wide a repertory as possible.

16
00:00:56,360 --> 00:01:00,110
So you should have mastery of say,
one or two languages.

17
00:01:00,110 --> 00:01:03,470
But also have many general
tools at the tip of your hands.

18
00:01:03,470 --> 00:01:06,660
You should especially learn
how to handle plain text.

19
00:01:06,660 --> 00:01:11,200
Many people, I've found, just don't know
how, when they're sent a plain text file,

20
00:01:11,200 --> 00:01:11,950
what to do with that.

21
00:01:11,950 --> 00:01:18,390
You should remember that it's easier to
test, you can have config files in that or

22
00:01:18,390 --> 00:01:21,940
the other thing that you should
remember is you would normally be

23
00:01:21,940 --> 00:01:26,450
accessing shells on your computer like
especially if you're Unix like computers.

24
00:01:26,450 --> 00:01:30,590
Learn how to handle those and
there are very powerful programs that

25
00:01:30,590 --> 00:01:34,020
the shells come with like find and
said and arc and create.

26
00:01:34,020 --> 00:01:37,130
Make sure that you know
them at least to an extent,

27
00:01:37,130 --> 00:01:39,940
because rather than writing
some long programs,

28
00:01:39,940 --> 00:01:44,180
you'll be able to adjust those
programs to do a lot of work for you.

29
00:01:44,180 --> 00:01:46,832
Similarly, if you are using a batch, or

30
00:01:46,832 --> 00:01:51,950
CSAs, then there are some batch
RC DCHRs like files that go with them.

31
00:01:51,950 --> 00:01:53,920
Learn about the details of those, and

32
00:01:53,920 --> 00:01:56,470
you'll be able to accomplish a lot by
knowing the intricacies of such things.

33
00:01:56,470 --> 00:02:00,480
And it's not a big learning curve,
it's fairly straight forward to learn.

34
00:02:00,480 --> 00:02:05,660
Just the very fact that they exist is not
known to many people, but once they get

35
00:02:05,660 --> 00:02:09,030
into it they realize how quickly they
can do a lot of things with those.

36
00:02:10,540 --> 00:02:14,070
Similarly with languages,
try to learn some languages that have

37
00:02:14,070 --> 00:02:17,520
completely different flavors,
some that you need to compile,

38
00:02:17,520 --> 00:02:21,160
some where spacing is important,
some in which spacing is not important.

39
00:02:21,160 --> 00:02:25,690
Because all of them have their strings and
then once you know some different types

40
00:02:25,690 --> 00:02:28,990
then you'll be able to use them in
different situations more efficiently.

41
00:02:30,330 --> 00:02:35,240
Again with editors, I'm sure that each
of you have some favorite editor and

42
00:02:35,240 --> 00:02:37,600
it's good to know that
as much as possible.

43
00:02:37,600 --> 00:02:40,680
But make sure that you know a couple
others at least to an extent.

44
00:02:40,680 --> 00:02:46,490
If you are very good eMax, try to learn
VI or Sublime or something like Nano.

45
00:02:46,490 --> 00:02:50,750
And you'll find that sometimes you'll
find using the editor quickly for

46
00:02:50,750 --> 00:02:54,900
something short is very useful or when
someone else is describing something to

47
00:02:54,900 --> 00:02:57,940
you in their favorite editor,
you'll be able to get that quite well.

48
00:02:59,210 --> 00:03:04,560
So each of these editors comes
with various interesting tools

49
00:03:04,560 --> 00:03:09,100
which are time-saving, like syntax
highlighting is possible these days,

50
00:03:09,100 --> 00:03:12,480
auto completion, auto indentation,
and various Boilerplates, and

51
00:03:12,480 --> 00:03:13,990
of course there is built in help.

52
00:03:13,990 --> 00:03:16,800
So, try to make sure you
understand of those.

53
00:03:16,800 --> 00:03:21,170
And, like was mentioned before,
you have cheat-sheets, even for editors.

54
00:03:21,170 --> 00:03:25,525
So make sure that you have those printed
out and put next to your work space so

55
00:03:25,525 --> 00:03:29,320
that you can take a look at
them whenever you want to.

56
00:03:29,320 --> 00:03:33,310
Then if you are trying to do some text
manipulation, language like Bowline,

57
00:03:33,310 --> 00:03:35,340
Ruby, are extremely
powerful in doing that so

58
00:03:35,340 --> 00:03:37,750
learned just a little bit
of those two languages.

59
00:03:39,140 --> 00:03:42,970
And there can be various code generators
that will help along in a big way.

60
00:03:42,970 --> 00:03:47,496
So small subroutines that can go with
this code generator can write most of

61
00:03:47,496 --> 00:03:49,490
your code quite easily.

62
00:03:49,490 --> 00:03:53,320
These also include shell scripts that can
be fairly easily written or config files.

63
00:03:53,320 --> 00:03:55,590
We talked about those
a little bit earlier.

64
00:03:56,860 --> 00:03:59,830
In our transient astronomy we
have something called we have

65
00:03:59,830 --> 00:04:01,880
built something called Skyalert.

66
00:04:01,880 --> 00:04:05,690
And when a new transient is found,
a transient is an object that changes in

67
00:04:05,690 --> 00:04:08,860
brightness and
we are interested in studying those.

68
00:04:08,860 --> 00:04:13,890
When a new transient is found
the Skyalert auto code generator,

69
00:04:13,890 --> 00:04:18,390
the active code generator goes out and
fetches data from various archives.

70
00:04:18,390 --> 00:04:21,820
And then, it incorporates those
data into the data that we

71
00:04:21,820 --> 00:04:23,550
farmed from the transient.

72
00:04:23,550 --> 00:04:27,260
And then, if certain conditions are made,
then it can do additional things like

73
00:04:27,260 --> 00:04:30,600
running some other programs or
raising an alert, et cetera.

74
00:04:30,600 --> 00:04:35,580
So, it becomes very handy, being able
to write such, active code generators.

75
00:04:35,580 --> 00:04:36,410
And it's not difficult,

76
00:04:36,410 --> 00:04:41,510
so that's definitely something that you
should try to make part of your portfolio.

77
00:04:42,930 --> 00:04:46,380
Then there are various
websites that you can visit,

78
00:04:46,380 --> 00:04:49,260
like the 99 bottles of beer website.

79
00:04:49,260 --> 00:04:53,710
It shows how to write that particular
program in various different programming

80
00:04:53,710 --> 00:04:57,280
languages and that allows you to
compare how those languages work and

81
00:04:57,280 --> 00:04:59,680
similarly there
are programming shoot outs.

82
00:04:59,680 --> 00:05:02,480
You can compare different
languages there that

83
00:05:02,480 --> 00:05:05,040
are of course various debates that go on.

84
00:05:05,040 --> 00:05:08,888
But here is a more objective look at
various features of different languages.

85
00:05:08,888 --> 00:05:12,440
Similarly Project Euler
is a fantastic resource.

86
00:05:12,440 --> 00:05:15,320
There, there is mathematically
problems of state aid and

87
00:05:15,320 --> 00:05:18,960
you're suppose to use programs to
solve them and once you solve them

88
00:05:18,960 --> 00:05:23,320
you get access to of the same program
written in other programming languages.

89
00:05:23,320 --> 00:05:27,460
They simply, in the site was hacked and
for some time that may not be available,

90
00:05:27,460 --> 00:05:33,190
but I'm sure that'll be coming back soon,
and it's a fantastic resource.

91
00:05:33,190 --> 00:05:35,290
You already saw earlier
about memorization.

92
00:05:35,290 --> 00:05:37,055
Definitely that's something
you should learn about,

93
00:05:37,055 --> 00:05:38,790
radius, caching digits, et cetera.

94
00:05:38,790 --> 00:05:42,570
I won't go into more
details of that right now.

95
00:05:42,570 --> 00:05:45,510
I'm going to leave you a bit,
a couple of exercises.

96
00:05:45,510 --> 00:05:46,330
It is an exercise.

97
00:05:47,330 --> 00:05:51,190
If you are given a certain amount and if
you want to find out how many ways there

98
00:05:51,190 --> 00:05:57,170
are of dividing that amount using say
the standard US coins pennies, nickels,

99
00:05:57,170 --> 00:06:01,450
dimes and quarters, that is coins of
denomination one, five, ten and 25.

100
00:06:01,450 --> 00:06:02,470
How can you do that?

101
00:06:02,470 --> 00:06:08,480
The problem is normally stated where you
want to divide 100 cents into 1s and

102
00:06:08,480 --> 00:06:09,980
5s and 10s and 25s.

103
00:06:09,980 --> 00:06:14,980
If you start with simply a one, if you are
separating a single penny into these four

104
00:06:14,980 --> 00:06:17,900
denominations, there'll be
only one way of doing that.

105
00:06:17,900 --> 00:06:20,230
Two, three, four, again,
there'll be one way of doing that.

106
00:06:20,230 --> 00:06:24,012
But the moment you come to five,
you can either get one coin of five, or

107
00:06:24,012 --> 00:06:25,050
five coins of one.

108
00:06:25,050 --> 00:06:25,960
So there are 2 ways.

109
00:06:25,960 --> 00:06:30,220
And then, as you go to higher numbers,
there'll be multiple ways of doing that.

110
00:06:30,220 --> 00:06:34,730
So the next part of the question, and this
is where you'll be able to build your,

111
00:06:34,730 --> 00:06:39,080
program is, you should answer this
question for all numbers from one to 100.

112
00:06:39,080 --> 00:06:45,500
And then, having answered that,
you should find out the ones that,

113
00:06:45,500 --> 00:06:50,320
which have, which return and odd number of
different number of ways of doing the sum.

114
00:06:50,320 --> 00:06:54,830
And then, you should simply
say whether the odd number of

115
00:06:54,830 --> 00:06:56,380
numbers that odd or even.

116
00:06:56,380 --> 00:06:58,170
So that's essentially an exercise so

117
00:06:58,170 --> 00:07:02,660
you should definitely try to take a,
give it a go.

118
00:07:02,660 --> 00:07:04,100
Here is another exercise.

119
00:07:04,100 --> 00:07:06,740
On lifehacker.com sometime
back a program was put

120
00:07:06,740 --> 00:07:09,390
out about a better strategy for hang man.

121
00:07:09,390 --> 00:07:12,620
Given a particular length of word
that you are looking for and

122
00:07:12,620 --> 00:07:15,760
given frequencies of letters
in different words how one

123
00:07:15,760 --> 00:07:18,860
can solve that in a meaningful and
easy fashion.

124
00:07:18,860 --> 00:07:22,160
I'd like you to try to solve the same
thing using only Unix commands.

125
00:07:22,160 --> 00:07:26,830
I mentioned a few earlier so
try to take a look at that.

126
00:07:26,830 --> 00:07:30,110
But that will stop back summarizing
one of the lessons that we

127
00:07:30,110 --> 00:07:33,560
may have learned from this
best programming practices.

128
00:07:33,560 --> 00:07:36,770
You should remember that a chain
is as weak as its weakest link so

129
00:07:36,770 --> 00:07:41,690
try to have your portfolio include
many strong of languages, and

130
00:07:41,690 --> 00:07:43,510
find the strong features of each of them.

131
00:07:45,900 --> 00:07:50,140
include a lot of comments wherever
possible, for yourself and for others.

132
00:07:50,140 --> 00:07:54,680
Make sure that you write lots and lots of
tests, that your programs are orthogonal.

133
00:07:54,680 --> 00:07:58,300
Don't duplicate yourself,
design by contract, and

134
00:07:58,300 --> 00:08:02,169
again, know the features of the language
of whatever module that you are using.

135
00:08:04,410 --> 00:08:09,360
In debugging, try to optimize your
programs in the way that we have told you

136
00:08:09,360 --> 00:08:11,510
about, not in arbitrary ways.

137
00:08:11,510 --> 00:08:14,730
Follow the best practices and
have fun coding.

138
00:08:14,730 --> 00:08:15,230
Thank you

