boilerplate

Java Remove repeated try, catch, finally boilerplate from DAO

青春壹個敷衍的年華 提交于 2019-11-30 21:51:19
I have a DAO class with many methods that have a lot of repeated code along the lines of: - public void method1(...) { Connection conn = null; try { //custom code here } catch (SQLException e) { LOG.error("Error accessing the database.", e); throw new DatabaseException(); } catch (QueryNotFoundException e) { LOG.error("Error accessing the database.", e); throw new DatabaseException(); } finally { if (conn != null) connectionPool.returnConnection(conn); } public void method2(...) { Connection conn = null; try { //different custom code here } catch (SQLException e) { LOG.error("Error accessing

Call methods using jQuery Plugin design pattern

倖福魔咒の 提交于 2019-11-30 12:14:23
问题 I've been using the jQuery Boilerplate for developing plugins and one thing I can't figure out is how to call methods from outside the plugin. For reference, here is the boilerplate code I'm talking about: http://jqueryboilerplate.com/ In my fiddle, http://jsfiddle.net/D9JSQ/2/ Here is the code: ;(function ( $, window, document, undefined ) { var pluginName = 'test'; var defaults; function Plugin(element, options) { this.element = element; this.options = $.extend( {}, defaults, options) ;

Call methods using jQuery Plugin design pattern

送分小仙女□ 提交于 2019-11-30 02:14:15
I've been using the jQuery Boilerplate for developing plugins and one thing I can't figure out is how to call methods from outside the plugin. For reference, here is the boilerplate code I'm talking about: http://jqueryboilerplate.com/ In my fiddle, http://jsfiddle.net/D9JSQ/2/ Here is the code: ;(function ( $, window, document, undefined ) { var pluginName = 'test'; var defaults; function Plugin(element, options) { this.element = element; this.options = $.extend( {}, defaults, options) ; this._name = pluginName; this.init(); } Plugin.prototype = { init: function() { this.hello(); }, hello :

Assign function arguments to `self`

你离开我真会死。 提交于 2019-11-28 22:55:19
I've noticed that a common pattern I use is to assign SomeClass.__init__() arguments to self attributes of the same name. Example: class SomeClass(): def __init__(self, a, b, c): self.a = a self.b = b self.c = c In fact it must be a common task for others as well as PyDev has a shortcut for this - if you place the cursor on the parameter list and click Ctrl+1 you're given the option to Assign parameters to attributes which will create that boilerplate code for you. Is there a different, short and elegant way to perform this assignment? I sympathize with your sense that boilerplate code is a

Scrap Your Boilerplate in f#

邮差的信 提交于 2019-11-28 20:49:29
I've used the Scrap Your Boilerplate and Uniplate libraries in the Haskell programming language, and I would find that form of generic programming over discriminated unions to be really useful. Is there an equivalent library in the f# programming language? Not that I know of; without support built-in to the language/compiler, I expect the only alternative is a reflection-based version. (I don't know how Uniplate is implemented - do you?) Here's the code for a reflection-based version based on the example from the original presentation. I have not thought deeply about its limitations, but this

Constructing simple Scala case classes from Strings, strictly without boiler-plate

邮差的信 提交于 2019-11-28 15:48:57
I seek succinct code to initialize simple Scala case classes from Strings (e.g. a csv line): case class Person(name: String, age: Double) case class Book(title: String, author: String, year: Int) case class Country(name: String, population: Int, area: Double) val amy = Creator.create[Person]("Amy,54.2") val fred = Creator.create[Person]("Fred,23") val hamlet = Creator.create[Book]("Hamlet,Shakespeare,1600") val finland = Creator.create[Country]("Finland,4500000,338424") What's the simplest Creator object to do this? I would learn a lot about Scala from seeing a good solution to this. (Note

Single-shot event subscription

倾然丶 夕夏残阳落幕 提交于 2019-11-28 09:58:24
I'm fairly convinced that this isn't possible, but I'm going to ask nonetheless. In order to make a single-shot subscription to events, I frequently find myself using this (self-invented) pattern: EventHandler handler=null; handler = (sender, e) => { SomeEvent -= handler; Initialize(); }; SomeEvent += handler; It's quite a lot of boiler-plate, and it also makes Resharper whinge about modified closures. Is there a way of turning this pattern into an extension method or similar? A better way of doing it? Ideally, I'd like something like: SomeEvent.OneShot(handler) It's not very easy to refactor

What is boilerplate code?

拈花ヽ惹草 提交于 2019-11-28 02:31:54
A coworker had never heard of this, and I couldn't provide a real definition. For me, it's always been an instance of 'I-know-it-when-I-see-it'. Bonus question, who originated the term? "boilerplate code" is any seemingly repetitive code that shows up again and again in order to get some result that seems like it ought to be much simpler. It's a subjective definition. The term comes from "boilerplate" in the newspaper industry: wiki NealB On the etymology the term boilerplate : from http://www.takeourword.com/Issue009.html ... Interestingly, the term arose from the newspaper business. Columns

Constructing simple Scala case classes from Strings, strictly without boiler-plate

谁说胖子不能爱 提交于 2019-11-27 09:35:14
问题 I seek succinct code to initialize simple Scala case classes from Strings (e.g. a csv line): case class Person(name: String, age: Double) case class Book(title: String, author: String, year: Int) case class Country(name: String, population: Int, area: Double) val amy = Creator.create[Person]("Amy,54.2") val fred = Creator.create[Person]("Fred,23") val hamlet = Creator.create[Book]("Hamlet,Shakespeare,1600") val finland = Creator.create[Country]("Finland,4500000,338424") What's the simplest

一些英文术语,不太能直译的那些

半腔热情 提交于 2019-11-27 06:24:20
那些不太能直译的... 1. bare metal data centres - 裸露的金属数据中心 data center 看得懂, 数据中心 bare - 裸露的, metal - 金属, 合金 所以连起来的意思是: A bare metal server is a physical server dedicated to a single tenant. wiki-link 区别于虚拟机和云主机. 指专门给一个tenant用的物理机. 2. Boilerplate - 烧水壶金属板 bolier - 烧水壶,热水器 plate - 碟,金属板 所以连起来的意思是: In computer programming, boilerplate code or just boilerplate are sections of code that have to be included in many places with little or no alteration. wiki link 指的是: 那些不得不到处写的代码片段, 这些代码必须要copy来copy去,很少需要修改. 来源: oschina 链接: https://my.oschina.net/joryqiao/blog/3134017