Besut Kode Challenge 1

download Besut Kode Challenge 1

If you can't read please download the document

Transcript of Besut Kode Challenge 1

Besut Kode
Challenge 1

add linting to mwparserfromhell

Your mission, should you choose to accept it

Build your online profile

Practise GCI tasks

Learn about Wikimedia,
a GCI participating organisation

This challenge is a real world example of how to build your online profile.

There are millions of projects that need extra linting added.

While linting, you will find bugs that can be added to the bug database, and then you can either fix yourself, or .. if it is too hard you can watch an expert fix it (and learn from them).

The minimum solution for this challenge is approximately a single advanced CGI task.

If you do it well, it is at least 10 GCI tasks, and possibly 20 GCI tasks.

Challenge environment

Using Github Classroom

You each have a private copy of mwparserfromhellMake mistakes

Not in public

Full administrator access to your copy

Best answers will be migrated to the public repositoryIt will appears on the Github profile of the selected participants

Only the best answer(s) will be guided in how to submit their changes to the real public mwparserfromhell project, to start their online profile.

Challenge 1: two parts

Add linting enforced by Continuous IntegrationIf you cant enforce a coding standard,
it is just a guideline. - jayvdb, and others

Update the least amount of code to pass the lint rules, with optimal rules enforced to minimise disruptionBeauty is in the eye of the beholder

However, least amount is not subjective

Part 1 raises the qualify bar for the mwparserfromhell project.

mwparserfromhell has good tests, however any new code that passes the tests is good enough. Currently a human must reject any messy new code submissions.
Humans are not good at meticulous checking.
And humans naturally avoid disagreement.

An automated check, with automated rejection, means the submitter must fix the problems. They can not argue with a computer.

But, your lint patch must be acceptable to Github user @earwig (Ben Kurtovic). He owns the repository. Unless he has indicated a coding guideline for mwparserfromhell, the only coding standard that exists is the code. The current code passes all of the implicit rules in Bens head.

Part 2 is a trick question. You should not ever change code just because a linter reports an error.

The only reason to change code is because you can prove that the code should be improved.

One justification for change is code inconsistency.

If all of the code is written in one style, except for one line, then fix that one line. If all of the code disagrees with a linting rule, you should disable that rule unless you can prove it found a bug.

Challenge 1: two languages

Choose either C and/or Python

Only one required to pass the challenge

Solve both to maximise your chance of winning the challenge

The languages C & Python are extemely different.

Both are general purpose.

Learn both to succeed as a programmer.

Language: C

Low- to Medium-level

General-purpose

Compiled to a single platform

Static

Structured imperative/procedural

Linting is hard, but many tools exist

If you dont know C, you dont understand computers.

You do not need to like C, but you must understand it.

The end.

---

https://commons.wikimedia.org/wiki/File:The_C_Programming_Language_logo.svghttps://commons.wikimedia.org/wiki/File:Pointers.svg

Language: Python

High-level

General-purpose

Interpreted by any platform

Dynamic

Object-oriented, functional, and imperative/procedural

Language is very simple

Very good lint tools that are simple to use

The point to stress is that Python is very dynamic. So dynamic it is crazy. But it is fun.

It is a simple language to learn functional programming.

It is a simple language to learn language theory.

Other recently created languages have many similar features, and are less crazy. Python is 25 years older and more mature. New languages come and go every year.

Languages like Perl and Php rot your brain.----https://commons.wikimedia.org/wiki/File:Python.svghttps://commons.wikimedia.org/wiki/File:Python_version_history_(1991-2015).svg

Automated linting services

https://github.com/integrations

So what are the linting problems to be solved in mwparserfromhell?

We dont need to open a text editor, or a command prompt.

Github integrates many online services that do the linting for us.

e.g. Code Climate on the bottom right.

Code Climate

https://codeclimate.com/dashboard

Code Climate consolidates the results from a suite of static analysis tools into a single, real-time report, giving your team the information it needs to identify hotspots, evaluate new approaches, and improve code quality.

Here are some projects I have in Code Climate.

Code Climate

https://codeclimate.com/github/earwig/mwparserfromhell

CSS Go JavaScript PHP Python Ruby

Apex CoffeeScript Ember ESLint Haskell Haxe RubyMotion Rails SCSS Swift Vim Script

Brakeman OSSBundler-AuditCoffeelintCSSLintDuplicationESLintFIXMENode Security Project (nsp)Pep8PHP Code SnifferPHP Mess DetectorRadonRuboCopApexMetricsEmber-watsonFoodcriticgofmtgolint...

It supports many languages and linters.

But it doesnt support C.

Code Climate

https://codeclimate.com/github/earwig/mwparserfromhell/issues

Some of the problems it finds

Code Climate

https://codeclimate.com/github/earwig/mwparserfromhell/issues
https://en.wikipedia.org/wiki/Cyclomatic_complexity

An explanation of the problem.

landscape.io

https://landscape.io/dashboard

Landscape.io is a python only service, but it is very good at Python.

It will only run checks on your own github repos, not earwigs repos

brechtm/citeproc-py is in my list because I am a committer on that project.

So, .

1. Fork an existing Github project2. Add a landscape.io project for your fork.

landscape.io

https://landscape.io/github/jayvdb/mwparserfromhell/1

All of you should already know that the linter tools dont like compat.py

landscape.io

https://landscape.io/github/jayvdb/mwparserfromhell/1/modules/mwparserfromhell/compat.py

Pretty colors!!

quantifiedcode.com

https://www.quantifiedcode.com/app/project/gh:jayvdb:mwparserfromhell

And here are some more online lint services that you can use....

scrutinizer-ci.com

https://scrutinizer-ci.com/g/jayvdb/mwparserfromhell/code-structure/develop/.

codacy.com

codacy.com

Here are some lint warnings that you probably havent ever seen.

sideci.com

blissai.com

Blissai supports the most languages, with many types of linters, including C.

blissai.com

Three similar linting tasks

setuptools dragons be there

html5lib-python watch and learn

Pywikibot test your theory, if you dare

I will not be giving any more general tips regarding the mwparserfromhell challenge...

Everyone sighs...WHAT?!?!

But I will show you three similar linting tasks for you to study and use in your solution for mwparserfromhell.

Example 1: setuptools

http://pypi-ranking.info/alltime

Dont try this one at home...

Setuptools is one of the most important tools in Python.

Setuptools ez_setup.py

https://bitbucket.org/pypa/setuptools/pull-requests/117https://phabricator.wikimedia.org/T87169

Pywikibot copies ez_setup.py from setuptools, with all of its lint violations.

Being a good internet citizen, I thought Ill fix the lint violations in setuptools.

Ouch! Declined.

Setuptools - mecurial

https://bitbucket.org/pypa/setuptools/pull-requests/157/activity

The author used mecurial, and mecurial was partially to blame for the mess.

Setuptools moved to github

https://github.com/pypa/setuptools/issues/489#issuecomment-216246073 https://github.com/pypa/setuptools/pull/567

Setuptools was moved to Github, and they start to become more open to fixes.

Setuptools @stepshal to the rescue

https://github.com/pypa/setuptools/pull/621

A nobody stepshal appears, with a few spelling corrections...

Setuptools 40 tasks later ...

https://github.com/pypa/setuptools/issues?utf8=%E2%9C%93&q=author%3Astepshal

That was merged, so @stepshal tried a few more...

Setuptools 40 tasks later ...

https://github.com/stepshal

@stepshal now has an awesome profile for a beginner, with setuptools on their resume.

setuptools

https://landscape.io/github/jayvdb/setuptools/1/messages/style

While setuptools still has many horrenous style problems yet to be fixed.

So, you could fix these, and have setuptools on your resume?

But I advise you : do not try your luck with setuptools.

Now consider: what if @earwig is like @jaraco ?

Will @earwig like your patch if it includes unnecessary changes? You must have a good reason to push your changes into his repository.

Example 2: html5lib-python

https://landscape.io/github/html5lib/html5lib-python

html5lib has a perfect score!

It already has CI linting using flake8 ....

html5lib-python: more linters

https://github.com/html5lib/html5lib-python/pull/292

So I submitted a pull request with many more flake8 checker plugins integrated, and pylint also enabled.

30 files modified!

You can watch my progress here live, this week.

html5lib-python:
is that lint, or a bug?

https://github.com/html5lib/html5lib-python/pull/292

One small linting message become a very large fix.

Nobody has used this script for a while, and it has bit rot.

Example 3: Pywikibot

15 years old

Supports Python 2.6 3.6, and PyPy

Optional dependencies, except for httplib2 or requests

Uses mwparserfromhell

I am one of the grumpy old men on the Pywikibot project.

Pywikibot: lots of lint messages

Pywikibot has many linters in place, but there are still many linting prolems to fix.

Look at the linting structure of this project, to understand Wikimedia python developers.

Each of you is welcome to submit one de-linting patch this week to Pywikibot, and I will review it within 24 hours.

Choose a problem that you need help with on your mwparserfromhell challenge.

Pywikibot - gotten worse!

Even some regressions occurring very recently.

Good luck.

Good luck.

After that: no more help from jayvdb.

Next: 10 private minutes.