旅行 写作 编程_我最喜欢的在旅行或没有互联网时保持编程的方式

旅行 写作 编程

This is a short guide on sharpening your skills and keeping productive when in transit. And it doesn’t involve burying your face in a book.

这是在运输过程中提高技能和保持生产力的简短指南。 它不涉及将脸埋在书中。

书只能带你走 (Books can only get you so far)

Now don’t get me wrong, I love a good programming book. Jon Duckett’s series on HTML, CSS, and JavaScript were the guiding beacons during my formative years as a Web Developer. Robert C Martin’s seminal tome Clean Code has its pages bent. It is misshapen through years of being wrung dry for each drop of information. Even Simon Holmes’ Getting MEAN, while now dated, had its time by my side in the local café. It was my companion as I created my first full-stack application.

现在不要误会我,我喜欢一本好编程书。 乔恩·达克特(Jon Duckett)关于HTML,CSS和JavaScript的系列文章是我在Web开发者成长初期的指导信标。 罗伯特·C·马丁(Robert C Martin)开创性的书目《清洁规范》(Clean Code)弯弯曲曲。 由于每一滴信息都被干了好几年,所以它的形状不正确。 即使是西蒙·福尔摩斯(Simon Holmes)的《 Getting MEAN》,尽管现在已经过时,但它在我身边的时间都在当地咖啡馆里。 在创建第一个全栈应用程序时,这是我的同伴。

With a little preparation, most of these books could’ve been used with no, or much more frighteningly, slow internet. Download the packages in advance. Get your local environments working. If the book’s comprehensive enough, you’ll likely make solid progress without needing Google, GitHub or StackOverflow.

稍作准备,这些书中的大多数本可以在没有互联网的情况下使用,或更可怕的是,互联网速度缓慢。 预先下载软件包。 使您的本地环境正常运行。 如果这本书足够全面,那么您可能会取得长足的进步,而无需Google,GitHub或StackOverflow。

On the flip-side, we as programmers thrive best when tasked with a challenge. Having an author walk us through solutions is nice, but it’s not enough. The best way for us to improve our problem-solving skills is to solve problems.

另一方面,当我们面临挑战时,我们作为程序员最擅长发展。 让作者指导我们完成解决方案是很好的,但这还不够。 我们提高解决问题能力的最好方法是解决问题。

If you’re a professional programmer then you’re likely to be solving your fair share of problems on a day-to-day basis. If you’re a hobbyist then you might find pleasure from creating your own JSF**k applications. Or even killing time by solving algorithm challenges online. It’s why sites like CodeWars or HackerRank are so popular.

如果您是专业程序员,那么您很可能每天都会解决很多问题。 如果您是一名业余爱好者,那么您可能会从创建自己的JSF ** k应用程序中找到乐趣。 甚至通过在线解决算法挑战来消磨时间。 这就是为什么像CodeWars或HackerRank这样的网站如此受欢迎的原因。

The underlying problem with most of these, particularly the latter, is continuing when the internet breaks. Or without connection to begin with. Both are common scenarios as developers are becoming more nomadic. How do you kill time during your 12-hour flight from London to Shanghai, while still reaping the rewards gained from solving problems?

当互联网中断时,其中大多数(尤其是后者)的潜在问题仍在继续。 或无连接开始。 随着开发人员变得越来越Nomad,这两种情况都是常见的情况。 从伦敦到上海的12小时飞行中,您如何打发时间,同时还能从解决问题中获得收益?

I have had the displeasure of being on such a long flight. There’s about enough space on said flight to prop your laptop on the foldout tray. Everything beyond that becomes a game of Tetris, trying to make your comfort and possessions fit in the limited space given to you on your budget flight. So you’ve got your laptop, headphones, jumper, snacks, and water all within arms reach? It’s starting to feel cramped, right? Try pulling out your 600 page 2-kilo programming book. Yeah, not gonna happen.

我很不高兴坐这么长的飞机。 上述航班上大约有足够的空间可将笔记本电脑支撑在折叠式托盘上。 除此之外的所有内容都变成了俄罗斯方块的游戏,试图使您的舒适感和财产适合预算飞行中给您的有限空间。 因此,您的手提电脑,耳机,跳线,零食和水都可以触及吗? 开始感到局促吧? 尝试取出600页的2公斤编程手册。 是的,不会发生。

银弹 (The silver bullet)

So how did I overcome this impediment? Well, I reimplemented the Lodash library.

那么我如何克服这一障碍呢? 好吧,我重新实现了Lodash库。

Why did I choose a such an arbitrary task? There are many key reasons. Some I rationalized before taking on the challenge and others I discovered along the way. Here are some of the most notable:

为什么我选择一个如此任性的任务? 有很多关键原因。 在挑战之前我合理化了一些,在此过程中发现了一些。 以下是一些最著名的:

  • Each function feels like a miniature code challenge

    每个功能都像一个微型代码挑战
  • The documentation is on a single HTML page, easy to download and view offline

    该文档位于单个HTML页面上,易于下载和离线查看
  • It encourages looking inside the source code when stuck

    鼓励在卡住时查看源代码
  • It allows you to build your own suite of utility functions

    它允许您构建自己的实用程序套件
  • It’s a library with no dependencies, which keeps things simple

    这是一个没有依赖关系的库,这使事情变得简单
  • You will get more familiar with your programming language of choice

    您将更加熟悉所选的编程语言

Let’s dive a bit more into each of these points.

让我们深入探讨这些要点。

每个功能都像代码挑战 (Each function feels like a code challenge)

As I mentioned earlier on, Codewars and HackerRack are two very popular programming challenge sites. For those unfamiliar, you’re given a programming task to complete within the built-in text-editor. When completed, you run your finished code against the curated suite of tests. The aim of the challenge is to get all tests passing.

正如我之前提到的,Codewars和HackerRack是两个非常流行的编程挑战网站。 对于那些不熟悉的人,您将获得一个编程任务,可以在内置的文本编辑器中完成该任务。 完成后,您可以对精选的测试套件运行完成的代码。 挑战的目的是使所有测试通过。

It’s not difficult emulating this yourself. If anything, it’s a great way of improving your approach to TDD (test driven development). My general approach to reimplementing a function would be to stub out the method:

自己模仿并不难。 如果有的话,这是改进TDD方法(测试驱动开发)的好方法。 我重新实现功能的一般方法是将方法存根:

const concat = (arr, ...otherParams) => {
  // if array is invalid throw error

  // handle no input for second parameter

  // add each item to a new array
    // flatten 1 level if item is array

  // return new array
};

const concat = (arr, ...otherParams) => {  // if array is invalid throw error  // handle no input for second parameter  // add each item to a new array    // flatten 1 level if item is array  // return new array};

const concat =(arr,... otherParams)=> {//如果数组无效则抛出错误//处理第二个参数没有输入// //将每个项目添加到新数组//如果item为数组则展平1级//返回新数组};

The next step is to create my test suite with some assertions I’d expect my function to satisfy:

下一步是使用一些我希望我的函数能够满足的断言来创建我的测试套件:

const concat = require('../concat');

describe('concat', () => {
  it('should return the expect results with valid inputs', () => {
    expect(concat([1, 2], [1], [2], 4939, 'DDD')).toEqual([1, 2, 1, 2, 4939, 'DDD']);
    expect(concat([], null, 123)).toEqual([null, 123]);
  });

  it('should throw errors with invalid inputs', () => {
    expect(() => concat(23, 23).toThrow(TypeError));
    expect(() => concat([1, 2, 3], -1).toThrow(TypeError));
  });

  it('should correctly handle strange inputs', () => {
    expect(concat([111], null, 'rum ham')).toEqual([111, null, 'rum ham']);
  });
});

Then I’d implement the code so the tests run successfully:

然后,我将实现代码,以便测试成功运行:

const { isValidArray } = require('../helpers');

const concat = (arr, ...otherParams) => {
  if (!isValidArray(arr)) throw new Error('Argument is not a valid array');

  if (otherParams.length === 0) return [];

  const concatenatedArray = otherParams.reduce((acc, item) => {
    if (isValidArray(item)) return [...acc, ...item];

    return [...acc, item];
  }, [...arr]);

  return concatenatedArray
};

Knocking out one of these functions will leave you with a sense pride and accomplishment.

剔除其中一项功能会使您感到自豪和成就感。

简单HTML文档 (Simple HTML documentation)

Most libraries have a GitHub page with an API reference. These are usually a single page of Markdown that’s available for download. Take a snippet from the Recompose library:

大多数库都有带有API参考的GitHub页面。 这些通常是Markdown的单个页面,可以下载。 从Recompose库中摘录一个片段:

branch() (branch())

branch(
  test: (props: Object) => boolean,
  left: HigherOrderComponent,
  right: ?HigherOrderComponent
): HigherOrderComponent

Accepts a test function and two higher-order components. The test function is passed the props from the owner. If it returns true, the left higher-order component is applied to BaseComponent; otherwise, the right higher-order component is applied. If the right is not supplied, it will by default render the wrapped component.

接受测试功能和两个高阶组件。 测试功能是通过所有者的道具传递的。 如果返回true,则left的高阶组件将应用于BaseComponent ; 否则,将应用right的高阶分量。 如果未提供该right ,则默认情况下将呈现包装的组件。

There’s plenty of information here to get you on your way. If you’re learning React and want to get your head around HOCs (higher order components), then implementing this library might be a gratifying challenge to take on.

这里有很多信息可以助您一臂之力。 如果您正在学习React并想了解HOC(高阶组件),那么实现这个库可能是一个可喜的挑战。

查看源代码 (Reviewing the source code)

Up until recently, I wouldn’t take much time to see how the packages I use most frequently work under the hood. Being without Google or StackOverflow made me desperate and so I started to look inside. I don’t know what I expected to see, but it wasn’t a minified, garbled mess.

直到最近,我都不会花很多时间来查看我最常使用的程序包如何在后台运行。 没有Google或StackOverflow令我感到绝望,所以我开始寻找内部。 我不知道我期望看到什么,但这不是一个混乱的小混乱。

Opening Pandora’s box didn’t send a swarm of scorn, hate and famine to taunt me and my family. Instead I was welcomed with cleanly written and well-documented code.

打开潘多拉魔盒,并没有嘲笑,仇恨和饥荒嘲弄我和我的家人。 取而代之的是,我编写了干净整洁的代码,对此表示欢迎。

You can even take a peek to see how the people at Lodash write their solutions differently to yours:

您甚至可以看一眼,看看Lodash的员工如何编写与您的解决方案不同的解决方案:

function concat() {
  var length = arguments.length;
  if (!length) {
    return [];
  }
  var args = Array(length - 1),
      array = arguments[0],
      index = length;

  while (index--) {
    args[index - 1] = arguments[index];
  }
  return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
}

You’ll learn new ways of achieving the same goals. Maybe their solutions are more efficient, maybe yours are. It’s still a great way to open your eyes to new paradigms and patterns.

您将学习实现相同目标的新方法。 也许他们的解决方案更有效,也许是您的。 仍然是您睁开眼睛看新范式和模式的好方法。

开发自己的实用程序功能 (Developing your own utility functions)

Lodash gets a bad rep as a library that has a large footprint. Projects may need a small number of the utilities. We will still import the whole library as a dependency.

Lodash作为一个拥有大量资源的库而获得了不好的代表。 项目可能需要少量的实用程序。 我们仍将整个库作为依赖项导入。

You could download the couple of functions that you use. Why not use the methods you spent 8 hours writing whilst flying over the Pacific Ocean? It might not be quite as robust. But you’ll always be reminded of your journey to Angular Fest Hawaii ’19 whenever you whip out your implementation of _.memoize.

您可以下载所使用的几个功能。 为什么不使用在太平洋上飞行时花费8个小时的写作方法呢? 它可能没有那么强大。 但是,每当您实现_.memoize的实现时,总会想起您前往Angular Fest Hawaii '19的_.memoize

保持简单 (Keep things simple)

Traveling’s draining and flying’s stressful. When feeling fatigued, any level of bureaucracy that sits in the way of any programming becomes a barrier. The idea is to choose a task that gets you coding with as little friction as possible.

旅行的排水和飞行的压力很大。 当感到疲倦时,妨碍任何编程的任何级别的官僚主义都会成为障碍。 这样做的想法是选择一个任务,使您的编码工作尽可能少。

I didn’t want to faff around with a bunch of random dependencies and messy vendor code when packed between two snorers on my overnight flight to Canada. It was a happy accident discovering that Lodash doesn’t rely on any external modules. The Lodash package itself is laid out simply. Each method has its own file, which may import a couple of base or utility methods.

当我隔夜飞往加拿大的两个打nor者之间时,我不想随便找一堆随机的依赖项和凌乱的供应商代码。 发现Lodash不依赖任何外部模块是一件很不幸的事情。 Lodash软件包本身的布局很简单。 每个方法都有其自己的文件,该文件可以导入几个基本方法或实用程序方法。

熟悉您选择的工具 (Becoming familiar with your tools of choice)

If you’re reading this article, chances are you’re familiar with JavaScript. Like most other modern programming languages, JavaScript receives semi-regular updates. These updates give you access to some new features. Implementing a library might take you to corners of your chosen language that you’ve never been before. It happened to me.

如果您正在阅读本文,那么您很可能熟悉JavaScript。 像大多数其他现代编程语言一样,JavaScript会接收半定期更新。 这些更新使您可以使用一些新功能。 实施一个库可能会让您陷入从未有过的选择语言的困境。 它发生在我身上。

In fact, I recently came across some of JavaScript’s newer built-in objects. I’d never used them in code before, so I made a conscious effort to integrate some of them into the utility methods I made:

实际上,我最近遇到了一些JavaScript的较新的内置对象 。 我以前从未在代码中使用过它们,因此我有意识地将它们中的一些集成到我制作的实用程序方法中:

const difference = (arr, ...otherArgs) => {
  if (!isValidArray(arr)) throw new TypeError('First argument must be an array');

  const combinedArguments = otherArgs.reduce((acc, item) => [...acc, ...item], [])
  if (!isValidArray(combinedArguments)) throw new TypeError('2nd to nth arguments must be arrays');

  const differenceSet = new Set([...arr]);
  combinedArguments.forEach(item => {
    if (differenceSet.has(item)) differenceSet.delete(item);
  });

  return [...differenceSet]
}

Using Set() makes a lot of sense here. What separates it from a normal array is that only unique values can be stored. This means you can’t have any duplicate values inside of your set. This works well when trying to create a function that removes duplicate values.

在这里使用Set()非常有意义。 它与普通数组的区别在于只能存储唯一值。 这意味着您的集合中不能有任何重复的值。 尝试创建删除重复值的函数时,此方法效果很好。

Whether you’re a guitarist, a painter, or a molecular physicist, you’re not going to get far without familiarizing yourself with your guitar, or your paints, or your … molecules?

无论您是吉他手,画家还是分子物理学家,如果不熟悉吉他,油漆或分子……,您将走不远。

The same goes with being a programmer. Master your tools and actively seek gaps in your knowledge. Make a conscious effort to implement features that you haven’t come across before. Or use ones that you find intimidating. It’s one of the strongest ways to learn.

成为程序员也是如此。 掌握您的工具并积极寻找知识方面的空白。 努力实现以前从未遇到过的功能。 或者使用您认为令人生畏的工具。 这是最强大的学习方式之一。

结论 (Conclusion)

This isn’t the only way to stay productive when without internet, but it’s worked well for me. In fact, it’s something I recommend people do in the early stages of their programming careers.

这不是在没有互联网的情况下保持生产力的唯一途径,但是对我来说效果很好。 实际上,我建议人们在编程生涯的早期阶段这样做。

I’d love to know if you’ve done something similar, or if you have your own ways of staying sharp without the internet. Let me know below!

我很想知道您是否做过类似的事情,或者您是否有自己的方法来在没有互联网的情况下保持敏锐。 让我在下面知道!

Do you know any other packages that would lend themselves well to being rewritten?

您是否知道其他任何软件包都可以被重写?

谢谢阅读! (Thanks for reading!)

Knowledge sharing is one of the cornerstones of what makes the development community so great. Please don’t hesitate to comment your solutions.

知识共享是使开发社区如此强大的基石之一。 请不要犹豫,评论您的解决方案。

If you’re interested in hosting me at a conference, meetup, or as a speaking guest for any engagement, then you can DM me on twitter!

如果您有兴趣主持我的会议,聚会或作为演讲嘉宾参加任何活动,则可以在twitter发给我DM!

I hope this article taught you something new. I post regularly, so if you want to keep up to date with my latest releases then you can follow me. And remember, the longer you hold the clap button, the more claps you can give. ???

我希望本文能教给您一些新的知识。 我会定期发布信息,因此,如果您想了解我的最新版本,可以关注我。 请记住,按住拍手按钮的时间越长,您可以拍的越多。 ???

Add a touch of Suspense to your web app with React.lazy()

使用React.lazy()向您的Web应用添加一丝悬念

How to use Apollo’s brand new Query components to manage local state

如何使用Apollo的全新查询组件来管理本地状态

No need to wait for the holidays, start Decorating now

无需等待假期,立即开始装修

Managing local state with Apollo and Higher Order Components

使用Apollo和高阶组件管理本地状态

The React Conference drinking game

React Conference饮酒游戏

Develop and Deploy your own React monorepo app in under 2 hours, using Lerna, Travis and Now

使用Lerna,Travis和Now在2小时内开发和部署自己的React monorepo应用

翻译自: https://www.freecodecamp.org/news/my-favorite-way-to-keep-programming-when-im-traveling-or-don-t-have-internet-d1c2d26618b7/

旅行 写作 编程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值