Skip to content

Perl 5 implementation - #4

Open
fedirsmilianets wants to merge 7 commits into
HowProgrammingWorks:masterfrom
fedirsmilianets:master
Open

Perl 5 implementation#4
fedirsmilianets wants to merge 7 commits into
HowProgrammingWorks:masterfrom
fedirsmilianets:master

Conversation

@fedirsmilianets

Copy link
Copy Markdown
Contributor

there is always more than one way to do it.

Somewhere perl lacks functionality, so i try to propose (readable) analogues.

@aqrln

aqrln commented Jun 8, 2017

Copy link
Copy Markdown
Contributor

Oh gosh... Perl. I don't even know who can review this.

Comment thread Perl_5/1-simple.pl Outdated
}
# everytime shift is called inside a function without array passed to shift operator
# it returns next argument
# note that shift is an operator, so it thinks of things next to it as of its arguments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please wrap the comment at 80 characters?

Comment thread Perl_5/1-simple.pl Outdated
sub inc1 {
return 1 + shift;
}
# everytime shift is called inside a function without array passed to shift operator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is better to have these comments above the corresponding functions, not below them.

Comment thread Perl_5/1-simple.pl Outdated
print inc2(2); # returns 3
print inc3(2); # returns 2 (look in comments near function definition)
print sum(1, 2); # returns 3
#print sum(1, 2, 3); # produces an error. Uncomment and try it!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd find it prettier to have a space after the hash.

Comment thread Perl_5/2-scopes.pl

use strict;
# in original repo this file is named "context"
# i take the responsibility to rename it to "scopes"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on this. Mind sending a PR to change it throughout the whole repo? I'd be in support for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it's a good idea.

Comment thread Perl_5/2-scopes.pl Outdated

my @cities = ("Athens", "Roma", "London", "Beijing", "Kiev", "Riga");

my $f = sub {return scalar @_;};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it more readable to have extra surrounding spaces inside the braces, but feel free to ignore this comment if the current style is idiomatic in Perl.

Comment thread Perl_5/5-default.pl Outdated
orDef(1, 2);
orDef(1);
orDef(1, 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Comment thread Perl_5/4-introspection.pl Outdated
@@ -0,0 +1,4 @@
#!/usr/bin/perl

print "Actually, perl cant introspect functions :(\n";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... I'd say we don't need this file at all, right?

@aqrln aqrln Jun 9, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... I'd say we don't need this file at all, right?

This comment is still unaddressed.

Comment thread Perl_5/6-spread.pl
use Data::Dumper;
# spread operator is not needed in perl
# because only way for us to get our params is through array
# but i'll show how to iterate through params

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should change the filename in this case.

@aqrln aqrln Jun 9, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should change the filename in this case.

This comment is still unaddressed.

Comment thread Perl_5/8-method.pl Outdated
return $a + $b;
}

# declarement of package is between package statements.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/declarement/declaration

Comment thread Perl_5/9-self.pl Outdated

use strict;
use Data::Dumper;
# i take the responsibility to rename this chapter too

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry about renaming. These files are not meant to copy the extract structure of the JavaScript samples. To the contrary, I find it detrimental that most people are doing exactly that thing instead of writing pieces of idiomatic code in a given language from scratch.

@fedirsmilianets

Copy link
Copy Markdown
Contributor Author

I hope now it's ready.

Comment thread Perl_5/1-simple.pl Outdated
use strict;
use v5.10;

# everytime shift is called inside a function without array passed to shift operator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap the line at 80 characters.

Comment thread Perl_5/1-simple.pl Outdated

# everytime shift is called inside a function without array passed to shift operator
# it returns next argument
# note that shift is an operator, so it thinks of things next to it as of its arguments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Comment thread Perl_5/10-lvalue.pl Outdated
use strict;
use v5.10;


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant empty line.

Comment thread Perl_5/4-introspection.pl Outdated
@@ -0,0 +1,4 @@
#!/usr/bin/perl

print "Actually, perl cant introspect functions :(\n";

@aqrln aqrln Jun 9, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... I'd say we don't need this file at all, right?

This comment is still unaddressed.

Comment thread Perl_5/4-introspection.pl Outdated
#!/usr/bin/perl

print "Actually, perl cant introspect functions :(\n";

@aqrln aqrln Jun 9, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A superfluous empty line. The text files in Unix are supposed to have one empty line at the end, not two of them :)

This comment is still unaddressed.

Comment thread Perl_5/6-spread.pl
use Data::Dumper;
# spread operator is not needed in perl
# because only way for us to get our params is through array
# but i'll show how to iterate through params

@aqrln aqrln Jun 9, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should change the filename in this case.

This comment is still unaddressed.

Comment thread Perl_5/1-simple.pl Outdated
# everytime shift is called inside a function without array passed to it
# it returns next argument
# note that shift is an operator, so it thinks of things next to it as of its arguments
# note that shift is a fucntion that awaits arguments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/fucntion/function

Comment thread Perl_5/4-introspection.pl Outdated
@@ -1,4 +0,0 @@
#!/usr/bin/perl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update the names of the other files so that there are no gaps in the ordering?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants